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. 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 website. Make sure on the New Web Site dialog that you have the .NET Framework 4.0 selected. And name it MyFirstEFProj.
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.
It will show you the Entity Data Model Wizard. EDM Wizard has two options 1 > Generate from database and 2> Empty model. Select the first option and hit next.
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.
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. Hit OK on the Connection Properties dialog.
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.
The next wizard lets you select the database objects to include in the EDM. Here you can select tables, views, and stored procedures.
Make sure both checkboxes available on wizards are checked and hit finish.
It will show you the generated EDM model in the Designer window. You have just created your first Entity Data Model generated from an existing database.