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:
- 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.
- Select the ADO.NET Entity Data Model item and complete the wizard.
- In the Add New Item dialog box, change the Name field to read NorthwindModel.edmx.
- Click Add.
- In the Choose Model Contents step, select Generate From Database and click Next.
- In the Choose Your Data Connection step, select the Northwind database.
- Change the Save Entity Connection settings in App.Config to read NorthwindEntities.
- Click Next.
- In the Choose Your Database Objects step, deselect Tables, Views, and Stored Procedures.
- Expand the Tables node and add a checkmark next to Customers, Orders, Order Details, and Products.
- 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 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.