It always feels exciting when you don’t have to do redundant work. I am currently looking at the best ways to create an ORM layer from an existing database without much overhead. Reading on Entity Framework, I like how easy it is to create the simple mapping classes for my tables.
These classes can then be used to fire CRUD (Create, Read, Update and Delete) operations on the tables. The detailed article on the approach I am demonstrating here is at this microsoft article: http://msdn.microsoft.com/en-us/library/vstudio/cc716703(v=vs.100).aspx but here is a quick 5 minute video demo on how to create the mappings from the database.
Here are the steps:
1. Open or create the project for which you want to create an .edmx file.
2. Right-click the project name in Solution Explorer, point to Add, and then click New Item.
3. Select ADO.NET Entity Data Model in the Templates pane.
4. Enter the name for the file (<project name>.edmx), and then click Add.
The first page of the Entity Data Model Wizard appears.
5. Select Generate from database in the Choose Model Contents dialog box, and then click Next.
6. Click the New Connection button.
The Connection Properties dialog box appears.
7. Enter the server name, select the authentication method, and enter the name of the database for which the model is being created. Click OK.
The Choose Your Data Connections dialog box is updated with the database connection settings.
8. Click Next to continue.
The Choose Your Database Objects dialog box appears. By default, no objects in the database are selected for inclusion in the .edmx file.
9. Expand the nodes for Tables, Views, and Stored Procedures. Cancel the selection of any tables, views, and stored procedures that you do not want included in the .edmx file.
10. Click Finish to create the .edmx file.
The Entity Data Model Wizard does the following:
* Adds references to the System.Data, System.Data.Entity, System.Core, System.Security, and System.Runtime.Serialization assemblies to the project, if they do not already exist.
* Generates an .edmx file that encapsulates the storage model, the conceptual model, and mappings.
* Creates a source code file that contains classes generated from the conceptual model. You can view the source code file by expanding the .edmx node in Solution Explorer.