Introducing ADO.NET Entity Framework (Cont.) Working with Beta 2 At the time of writing, Visual Studio 2008 Beta 2 is available as are ADO.NET Entity Framework Beta 2 and the ADO.NET Entity Framework Tools CTP 1. Eventually ADO.NET Entity Framework and its tools will be part of Visual Studio 2008, but currently it is necessary to install all three pieces. See the sidebars for the appropriate links. | " | It is important to note that you will need to do manual editing of the EDMX file for more complex scenarios.
| " |
The tools contain a wizard for creating a model from a database and a designer for editing the model. Since the tools are still currently in their first Community Technical Preview, expect them to evolve rapidly over the next few releases. Build a Simple Entity Data Model The first steps of learning ADO.NET Entity Framework involve using the wizard to create a simple Entity Data Model from an existing database. To follow these steps, it will be necessary not only to have the above programs and tools installed, but to also have access to a SQL Server or SQL Server Express database, so that you can create a simple EDM in a simple Windows Form application. - Start by creating a new Windows Form project, and then add a new item to the project.
- In the item templates, select “ADO.NET Entity Data Model” which will open up the wizard.
- Click the database option as you will be creating an EDM from an existing database.
- On the next page of the wizard, shown in Figure 2, use the database drop-down list to select from an existing database connection or to create a new one on the fly. This example is based on the Northwind database.
- On this page, you have an opportunity to create a name that will be used for the Connection string in the application’s config file as well as for the main class that will give us access to the entities we are about to create. For this sample, I have renamed this “NWEntities”.
- On the last page, shown in Figure 3, you will have the ability to select which tables, views, or stored procedures from the database to include in the model. By default all are selected. For this example, leave all of the items selected, and then let the wizard finish its job.
 Figure 2: Adding a new Entity Data Model to your project. Figure 3: Selecting a database (in this case, a SQL Server Express database) to build your Entity Model from. Note the additional metadata in the connection string that the newly created subsequent classes will use.The Visual EDM Designer When the wizard is complete, you will see the new Model1.EDMX file. Double-clicking on the EDMX file will open up the model in the designer. The Tools CTP was released just before this article went to print and therefore, the article will not spend much time looking at the designer beyond a screenshot displayed in Figure 4. This is a section of what the model from the Northwind database will look like after the wizard has built it from the database.  Figure 4: Part of the view of the model generated from the Northwind database in the Entity Data Model Designer.You can see that each entity is represented along with its properties and its relationships to other entities. The model displays the conceptual layer only and has an interface for mapping to the entities in the storage layer. For links to more information about the designer, check the sidebar. | & | | Resources
ADO.NET Orcas Forums http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=533&SiteID=1 ADO.NET Team Blog http://blogs.msdn.com/adonet Project Astoria http://blogs.msdn.com/astoriateam/archive/2007/07/18/welcome.aspx Data Access Incubation Projects http://msdn2.microsoft.com/en-us/data/bb419139.aspx The LINQ Project http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx MSDN Data Platform Developer Center http://msdn2.microsoft.com/data |