<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vince Plaza&#039;s Blog &#187; Entity Framework (EF)</title>
	<atom:link href="http://www.vinceplaza.com/category/entity-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vinceplaza.com</link>
	<description>Microsoft .NET programming ideas and samples</description>
	<lastBuildDate>Sat, 13 Mar 2010 00:07:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Update EF Model Properties to Match Conceptual Model</title>
		<link>http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/</link>
		<comments>http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 23:21:34 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Entity Framework (EF)]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=75</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>Before reading this post, read the previous post: <a href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/">Create an Adventure Works Entity Framework Model</a></p>
<p>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.</p>
<p>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:</p>
<div id="attachment_79" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-79" href="http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/ef_selecteftableandpropertiespane/"><img class="size-medium wp-image-79" title="Select EF Table and Properties Pane" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_SelectEfTableAndPropertiesPane1-300x216.jpg" alt="(click to enlarge)" width="300" height="216" /></a><p class="wp-caption-text">(click to enlarge)</p></div><br />
<span id="more-75"></span><br />
The change we are going to make is simple. Change the text in the Entity Set Name field to SalesOrderDetails. Doing this will allow us to differentiate between a single SalesOrderDetail and a set of details in our code and in Intellisense. Do the same thing for SalesOrderHeader, changing the plural value to SalesOrderHeaders. Change the Entity Set Name of the SalesPerson table to SalesPeople.</p>
<p>If you name your database tables with plural names like I do, you will notice one annoying feature of Entity Framework. If you change the Name value, lets say, from SalesPeople to SalesPerson, the designer will automatically change the Entity Set Name to SalesPersonSet. You will need to set it back to your plural value each time.</p>
<p>We will now change the name of the relationships to match our intention. The relationships are found at the bottom of the table under navigation properties. Starting with the SalesPerson table, right click the SalesOrderHeader relationship and select Rename in the context menu. Rename the relationship to SalesOrderHeaders by adding an &#8220;s&#8221;. In the SalesOrderHeader table, rename the relationshiop SalesOrderDetail to SalesOrderDetails. This is actually the beauty and intent of using the Entity Framework. I recommend seeing what happens when you change column name, table name and other properties as well, but this is all we need to do to support the upcoming samples.</p>
<p><div id="attachment_81" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-81" href="http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/ef_adventurworksdatamodelwithnewentitysetnameprops1/"><img class="size-medium wp-image-81" title="AW Datamodel with new Entity Set Name Properties" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_AdventurworksDatamodelWithNewEntitySetNameProps11-300x194.jpg" alt="(click to enlarge)" width="300" height="194" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>The following code snippet shows how you will reference the newly named properties in code:</p>
<p><code>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using Models;<br />
namespace ViewModels<br />
{<br />
    public class SalesOrderViewModel: ViewModelBase<br />
    {<br />
        private AdventureWorksEntities context;<br />
        private SalesOrderHeader currentSalesOrder;<br />
        public SalesOrderViewModel()<br />
       {<br />
            context = new AdventureWorksEntities();<br />
        }<br />
        private void SetCurrentSalesOrder(int SalesOrderId)<br />
        {<br />
            currentSalesOrder = context.SalesOrderHeaders.Where(so =&gt; so.SalesOrderId == SalesOrderId).FirstOrDefault();<br />
        }<br />
    }<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/13/update-ef-model-properties-to-match-conceptual-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create an Adventure Works Entity Framework Model</title>
		<link>http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/</link>
		<comments>http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 22:46:46 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Entity Framework (EF)]]></category>

		<guid isPermaLink="false">http://www.vinceplaza.com/?p=18</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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:</p>
<p>Right click on the Model folder in the Solution Explorer, select Add and then select New Item from the context menu.</p>
<div id="attachment_49" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-49" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_addnewitemcontextmenu/"><img class="size-medium wp-image-49" title="Add New Item Context Menu" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_AddNewItemContextMenu-300x251.jpg" alt="(click to enlarge)" width="300" height="251" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>Select the ADO.Net Entity Data Model template and name it AdventureWorks.edmx.</p>
<div id="attachment_54" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-54" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_newadventureworksedmxdialog/"><img class="size-medium wp-image-54" title="Choose the ADO.NET Entity Model Template" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_NewAdventureWorksEdmxDialog-300x164.jpg" alt="(click to enlarge)" width="300" height="164" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p><span id="more-18"></span><br />
On the next dialog, create a connection to the AdventureWorksdatabase you plan on using, or select sn existing one using the drop down. Use the default recommendation for naming and storing the connection string in the App.config file. In my case, the connection name is prefixed with Milo because that is the name of my local machine.</p>
<div id="attachment_57" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-57" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_chooseyourdataconnectiondialogforaw/"><img class="size-medium wp-image-57" title="Create or Select your AW Data Connection" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_ChooseYourDataConnectionDialogForAW-300x266.jpg" alt="(click to enlarge)" width="300" height="266" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>On the next dialog, select the option to create a model from a database.</p>
<div id="attachment_58" class="wp-caption alignnone" style="width: 310px"><a rel="attachment wp-att-58" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_generatefromdatabasedialog/"><img class="size-medium wp-image-58" title="Generate the AW Model from a Database" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_GenerateFromDatabaseDialog-300x266.jpg" alt="(click to enlarge)" width="300" height="266" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>Then select the tables you want to include. I selected three tables from the Sales schema for this example.</p>
<p><a rel="attachment wp-att-59" href="http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/ef_choosedatabaseobjextsdialog_awsalestables/"><img class="alignnone size-medium wp-image-59" title="EF_ChooseDatabaseObjextsDialog_AWSalesTables" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_ChooseDatabaseObjextsDialog_AWSalesTables-300x266.jpg" alt="EF_ChooseDatabaseObjextsDialog_AWSalesTables" width="300" height="266" /></a></p>
<p>That is all there is to it. The model should open up in the GUI designer.</p>
<div id="attachment_68" class="wp-caption alignnone" style="width: 310px"><a href="http://www.vinceplaza.com/?attachment_id=68"><img class="size-medium wp-image-68" title="Finished Adventure Works EF Model With Sales Tables" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_FinishedAdventureWorksEFModelWithSalesTablesSmall-300x244.jpg" alt="(click to enlarge)" width="300" height="244" /></a><p class="wp-caption-text">(click to enlarge)</p></div>
<p>In the next post I will show a couple of property changes I make to support future samples that use the model.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/11/create-an-adventure-works-entity-framework-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resetting metadata references in Entity Framework connection strings</title>
		<link>http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/</link>
		<comments>http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 01:49:24 +0000</pubDate>
		<dc:creator>Vince Plaza</dc:creator>
				<category><![CDATA[Entity Framework (EF)]]></category>

		<guid isPermaLink="false">http://www.plazaconsulting.net/blogs/vinceplaza/?p=3</guid>
		<description><![CDATA[I needed to move a couple of Entity Framework edmx files into a new project directory. Although I used the &#8220;add existing item&#8221; 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 [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to move a couple of Entity Framework edmx files into a new project directory. Although I used the &#8220;add existing item&#8221; 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: &#8220;Unable to load the specified metadata resource.&#8221; 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.</p>
<p>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 &#8220;Metadata Artifact Processing&#8221;.</p>
<div id="attachment_8" class="wp-caption alignleft" style="width: 290px"><a rel="attachment wp-att-8" href="http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/ef_metadataartifactprocessing/"><img class="size-medium wp-image-8" title="EF_MetadataArtifactProcessing" src="http://www.vinceplaza.com/wp-content/uploads/2009/08/EF_MetadataArtifactProcessing-280x300.jpg" alt="Screenshot of VS2008 designer and properties pane" width="280" height="300" /></a><p class="wp-caption-text">Screenshot of VS2008 designer and properties pane</p></div>
<div class="mceTemp mceIEcenter"> </div>
<p>The default value for this property is &#8220;Embed in Output Assembly&#8221; and this appears to be accepted as the best default practice. To repair your metadata reference, though, change the value to &#8220;Copy to Output Directory&#8221; and build the project. Now set the value back to the original &#8220;Embed in Output Assembly&#8221;.  Build the project again and you should be set to go. As this updates the App.config file, don&#8217;t forget to copy the updated entries to other projects that rely on the setting at run time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinceplaza.com/2009/08/09/resetting-metadata-references-in-entity-framework-connection-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
