Creating an ADO.NET Entity Framework Entity Data Model
Originally published on DataDeveloper.net
In this tutorial, you will create a new Entity Data Model inside an Class Library Project. The data model will be built from the AdventureWorksLT database.
The project can be used in (Windows, Console, Web, other class libraries etc) by referencing this project.
Create a new Class Library Project
- Select New Project from File Menu option
- Select your preferred project base: e.g. Visual Basic or C#
- Select Class Library
- Change the name of the application in the Name text box to DataDevEDM
- Click OK
Add an Entity Data Model Item
- In Solution Explorer, right click the project name.
- Click Add on the context menu that opens.
- Click New Item.
- In the Add New Item dialog, click ADO.NET Entity Data Model.
- Change the name from Model1.edmx to AWModel.edmx
- Click the Add button
- In the Entity Data Model Wizard click Generate from Database, then click the Next button
Create a database connection for the Entity Data Model
If you have a database connection already created in Visual Studio, skip to Define Contents of an Entity Data Model
- On the Choose Your Data Connection page of the wizard, click the New Connection button.
- At the top of the connection properties window, click the Change button next to the Data Source
- Select Microsoft SQL Server Database File from the Data source list, then click OK
- Click the Browse button to the right of Database file name
- Browse to the folder where you have saved the AdventureWorksLT database*.
- Select AdventureWorksLT.mdf then click Open.
- At the bottom of the Connection Properties window, click OK
Define the contents of an Entity Data Model
- Select the database connection from the drop down.
- At the bottom of the Entity Data Model Wizard window, change the value of Entity connection settings to AWEntities then click Next.
- On the next page, change the Model Namespace to AWModel.
- Check Tables, Views and Stored Procedures.
This will include all of the items. You can expand these nodes to select only the specific tables, views and stored procedures that you want.
- Click Finish.
- Note that in the solution explorer, a new file, AWModel.edmx has been created.
View the model
- Double click the AWModel.emx file to open the model in the Entity Data Model designer.