Create A Database Using the ADO Entity Framework
SetupIf you have not already done so, open Visual Studio and start a new web project.
Step 1The first step we will do is design the database we have in mind. Lets come up with a simple design for a person. A Person will have an ID, a Name, and a City associated with them. Right click on the solution and select, Add New Item.
You are to select Entry Data Model and name it as you wish. We kept it as Model for the sake of this tutorial. It will ask you if you would like the model within the App_Code folder, we usually allow it, however you may want it in a folder of your own choice. Everyone is different.
You will then be prompted to choose whether you want to generate the model from a pre-made database or if you would like an empty model. Since we don’t have a database as of yet, lets choose the Empty Model. You will end up with a blank canvas, now for the fun part.
Step 2Right click on the designer surface and select Add and choose Entity. Name the Entity, Person. Automatically it will set up the ID to be the primary key, this is fine. Finish the set up and you will now have one table on the designer surface. Right click on the table and select Add->Scalar Property. Name the property Name. Do the same thing except name this new property, City. Save the changes done to the model. You should now have a table as the image below presents:
Step 3The last step we will take is the creation of the database. This part is actually the easiest part since everything is already defined within the model. Right click on the solution and select Add New Item, select a new Sql Database and click OK. After this, go back to the model and right click on the table and select, “Generate Database From Model”. From here you will configure the model to the Database and the Generate Database Wizard will show you the Query used to execute the command.
So long as you have full access to your local system or a particular database, everything should work out. Otherwise, contact your system administrator for further assistance.
A Few Last Words…There are multiple applications to today’s lesson, it all depends on what sort of project you are working with. Thank you for being a valued reader and join us next time for additional database tutorials! Till then…
We used over 10 web hosting companies before we found Server Intellect. Our new server with cloud hosting,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect’s customer support and assistance are the best we’ve ever experienced.