Home > Articles > Programming > C#

  • Print
  • + Share This
From the author of

Defining an Entity Data Model

After you install the Entity Framework beta bits, you'll see an ADO.NET Entity Data Model applet in the New Items dialog box. You can add an entity data model (EDM) to any kind of project. For simplicity, create a console application and follow these steps to use the ADO.NET EDM wizard to create an EDM for you:

  1. Assuming that you've downloaded the Entity Framework beta bits, have Visual Studio 2008, and have created a console application, select Project > Add New Item in Visual Studio.
  2. Select the ADO.NET Entity Data Model item and complete the wizard.
  3. In the Add New Item dialog box, change the Name field to read NorthwindModel.edmx.
  4. Click Add.
  5. In the Choose Model Contents step, select Generate From Database and click Next.
  6. In the Choose Your Data Connection step, select the Northwind database.
  7. Change the Save Entity Connection settings in App.Config to read NorthwindEntities.
  8. Click Next.
  9. In the Choose Your Database Objects step, deselect Tables, Views, and Stored Procedures.
  10. Expand the Tables node and add a checkmark next to Customers, Orders, Order Details, and Products.
  11. Change the Model Namespace to NorthwindModel and click Finish.

After you click Finish, Visual Studio generates some code to create an Entity Data Model XML (.EDMX) file, the source code that represents your entities and entity relationships. The results should look something like Figure 1.

Figure 1

Figure 1 The Entity Data Model designer showing the Customers, Orders, Order_Details, and Products (out of view) tables and their relationships.

The Model Browser on the right will explore the entity types, associations, tables, and other elements that may be in your model. All you have to know at this point is how to write a LINQ query.

  • + Share This
  • 🔖 Save To Your Account