Database creation from strict queries and or from table to table are only two of the ways to create databases. There is also a way to create a database from a model. In this tutorial, you will learn how to create a database from an ADO Entity Model.


If you have not already done so, open Visual Studio and start a new web project.

Step 1

The 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 2

Right 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 3

The 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.

Click Finish

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!

Download Source Files