SIGN UP MEMBER LOGIN:    
ARTICLE

Creating an Entity Data Model (Entity Framework 4.0)

Posted by Mukesh Kumar Articles | ADO.NET in C# February 22, 2011
The ADO.NET Entity Framework is a new data access platform from Microsoft for writing .NET applications. It is a set of technologies in ADO.NET that helps fill in the space between object-oriented.
Reader Level:
Download Files:
 


What is Entity Framework?

The ADO.NET Entity Framework is a new data access platform from Microsoft for writing .NET applications. It is a set of technologies in ADO.NET that helps fill in the space between object-oriented development (objects) and databases. Basically it is an Object-Relational Mapping (ORM) method of mapping relational databases and object-oriented programming languages implemented using .Net.

With Entity Framework 1.0 (the previous version of EF) you could only generate a model from an existing database, and you could also start with an empty model and create the conceptual model from scratch but you could not create the database from that model. Using Entity Framework 4.0 you can create an empty EDM (Entity Data Model) and then generate the database, mappings, and classes from the defined model. And it allows you to use the Entity Framework using Plain Old CLR Objects (POCO) entities without an EDMX file.

Database-First Approach

Open Visual Studio 2010 and create a new web site. Make sure on the New Web Site dialog that you have the .NET Framework 4.0 selected. And name it MyFirstEFProj.

EntDataModel1.gif

Now open solution explorer and right-click on the project. Select Add New Item from the context menu. This will open the Add New Item dialog. Select the ADO.NET Entity Data Model template and click Add.

EntDataModel2.gif

It will show you Entity Data Model Wizard. EDM Wizard has two options 1 > Generate from database and 2> Empty model. Select first option and hit next.

EntDataModel3.gif

In the next wizard you have to specify the data connection for your EDM. If you have created a connection previously it will show you the list. If you haven't you will need to create one. Click on the New Connection button.

EntDataModel4.gif

It will open the Connection Properties dialog. The Connection Properties dialog looks very similar to SQL Server connection dialogs. You need to provide the server name, authentication method (Windows for SQL Server authentication), and the database name and click the Test Connection button to make sure all the connection settings are correct. And hit OK on the Connection Properties dialog.

EntDataModel5.gif

It will take you back to the EDM connection wizard with your new connection. There are two radio buttons on this wizard. The two states that you will either include the username and password in the connection string or you will set the username and password in your code. One of the options should be enabled.

EntDataModel6.gif

The next wizard lets you to select the database objects to include in the EDM. Here you can select tables, views, and stored procedures.

EntDataModel7.gif

Make sure both checkboxes available on wizard are checked and hit finish.

EntDataModel8.gif

It will show you generated EDM model in the Designer window. You have just created your first Entity Data Model generated from an existing database.

erver'>
Login to add your contents and source code to this article
share this article :
post comment
 

Nice Article

Posted by Jaganathan Bantheswaran Feb 22, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor