Sunday, June 21, 2009

Model First Development using VS.NET 2010 Beta 1 & Entity Framework

Until VS.NET 2010 Bea1 Released we have been creating our model from Existing Database. Now we are going to take the route  from Model First then Create our Persistence  Layer or Database.

Step1 :  First Create ASP.NET Web Application  ( you can use other .NET project as well).


Step 2: Now add ADO.NET Entity Data Model to the project we just created above.


Now the  Entity Data Model Wizard will gives two options in that now we are going to select Second option called Empty Model

(VS.NET 2008 SP1 this options was there but it was not working)


Now we can start creating our Entities and Define the Relations among them.


Now Right click on the  Design surface and start adding entity and properties and type. Here for the heck i am taking simple example School , Player, Game et..

I am going to create the 4 Entities namely   SCHOOL, PLAYER, GAME, STADIUM and Define the relations between them.

image image



Now we have Created our Entities ,their properties and relations. now time to generate  database for our model to map to. This is what  i like Microsoft  IDE and tools so simple to create and Develop. Now Right click on the model designer area and click “Generate Database Script From Model… as shown above.

Now you will asked to select   DB Server name.[ The standard database connection dialog we are all used to in Visual Studio when  Adding a connection]image

Now you need to cut the generated script and paste into SQL server Management Studio and execute it against your database.  The database itself will have been created, but in this beta version you still need to execute the scripts manually.  This will not be the case in the final version of VS.NET 2010.

Here is the Relational Model




No comments: