Saturday, December 4, 2010

Entity Framework Model First

With Entity Framework it is possible to develop a model first and then derive at a database.

In the Entity Data Mode Wizard select Empty Model.





This action will instantiate the Entity Model Designer with its associated toolbox which contains options for creating Entity, Association and Inheritance.

For creating an Entity double click on Entity from the toolbox.

We are in the process of creating a many to many relationship. I am going to take Marriage Hobbyist as the sample. Here I am going to track the marriages of Marriage Hobbyists like Elizabeth Taylor, Richard Burton, Tom Cruise, Sasi Taroor, etc. I am creating two Entities Gentleman and Lady. The association here is Many to Many.  Here a Entity called Elizabeth Taylor have multiple marriages with Richard Burton, Conrad Hilton, etc. And Richard Burton in turn have multiple marriages with Elizabeth Taylor, etc.






















..




















..




















By default the association is One to Many Instead I am selecting *(Many) from the Multiplicity attribute of Gentleman Entity.




















In effect a  Many to Many Association between Gentleman and Lady as shown in the diagram.
























You are expected to create a database as shown below. Once you have done that you can select Generate Database from Model by right clicking on the Model Designer surface.




















..




















You can see the database Script generated for you.




















Here is the output of running the script and opening the table in Database Diagram. Here you can see Gentleman, Lady as well as the junction table GentlemanLady.






















Now you can use the Asp .Net Dynamic Data Project for easily creating a Project for MarriageHobbyists.

No comments:

Post a Comment