Vince Plaza's Blog

...Microsoft .NET programming ideas and samples

Entity Framework (EF)

...now browsing by category

 

Update EF Model Properties to Match Conceptual Model

Thursday, August 13th, 2009

Before reading this post, read the previous post: Create an Adventure Works Entity Framework Model

Now that you have created an Entity Framework model for the Adventure Works database, you can begin to update properties to align the model with your business. In this example, I will change a few simple table properties to support future samples that use the model.

To start, open the AdventureWorks.edmx file in the Visual Studio GUI design tool. Select the SalesOrderDetail table by clicking on the table just below the table name in the header. The properties pane should look like this:

(click to enlarge)

(click to enlarge)


Click to continue »

Create an Adventure Works Entity Framework Model

Tuesday, August 11th, 2009

It is easy to create a simple Entity Framework model using the Adventure Works SQL Server database. I will use a WPF Model View project as my container. To start, create a new WPF Model View Application as described in this posting:

Right click on the Model folder in the Solution Explorer, select Add and then select New Item from the context menu.

(click to enlarge)

(click to enlarge)

Select the ADO.Net Entity Data Model template and name it AdventureWorks.edmx.

(click to enlarge)

(click to enlarge)

Click to continue »

Resetting metadata references in Entity Framework connection strings

Sunday, August 9th, 2009

I needed to move a couple of Entity Framework edmx files into a new project directory. Although I used the “add existing item” functionality of VS 2008, I still managed to corrupt the connection string entries in the App.config file, likely by using a subfolder. This led to a string of the following error message when I tried to run the app: “Unable to load the specified metadata resource.” After searching for a fix, I found that by toggling a property of the edmx file, it is possible to realign the connection to the new project.

To do this, open the model in the Visual Studio GUI tool for editing edmx files. Use your cursor to select any point in the background of the diagram where there is not an object. If you look at your properties pane, you will notice a property for the diagram called “Metadata Artifact Processing”.

Screenshot of VS2008 designer and properties pane

Screenshot of VS2008 designer and properties pane

 

The default value for this property is “Embed in Output Assembly” and this appears to be accepted as the best default practice. To repair your metadata reference, though, change the value to “Copy to Output Directory” and build the project. Now set the value back to the original “Embed in Output Assembly”.  Build the project again and you should be set to go. As this updates the App.config file, don’t forget to copy the updated entries to other projects that rely on the setting at run time.