Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Introducing ADO.NET Entity Framework : Page 2

The ADO.NET Entity Framework is core technology in Microsoft's evolving data platform that bridges the gap between data structures and objects in your applications.


advertisement
Working with Beta 2
At the time of this writing, Visual Studio 2008 Beta 2 is available, as are ADO.NET Entity Framework Beta 2, and the Entity Framework Tools CTP1. 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. The tools contain a wizard for creating a model from a database, and a designer for editing the model. As 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, you must not only have the programs and tools mentioned above installed, but you must also have access to a SQL Server or SQL Server Express database, so that you can create a simple EDM in a basic Windows Form application.

 
Figure 2: Adding a new Entity Data Model to your project.
  1. Start by creating a new Windows Form project, and then add a new item to the project.
  2. In the item templates, select "ADO.NET Entity Data Model" to open the wizard.
  3. Click the database option as you will be creating an EDM from an existing database.
  4. 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.
  5. 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."
  6.  
    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.
  7. 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.
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; it has an interface for mapping to entities in the storage layer. For links to more information about the designer, see the Resources sidebar.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap