<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ADO.NET team blog : Entity Framework</title><link>http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx</link><description>Tags: Entity Framework</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Automatic Generation of Stored Procedure Return Types</title><link>http://blogs.msdn.com/adonet/archive/2009/11/12/automatic-generation-of-stored-procedure-return-types.aspx</link><pubDate>Thu, 12 Nov 2009 20:07:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9921549</guid><dc:creator>dpblogs</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9921549.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9921549</wfw:commentRss><description>&lt;p&gt;A new feature of the Entity Framework in .NET 4.0 is the ability to return collections of complex type instances from stored procedures. In the next public release of the designer, we have enriched this functionality by adding the ability to automatically create these complex types by querying stored procedure metadata from the database server. To demonstrate this feature, we will use the Northwind database, and we will focus on a stored procedure called “CustOrdersDetail”. Looking at the designer’s model browser window after we reverse engineer Northwind, we see:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Untitled" border="0" alt="Untitled" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_thumb.png" width="166" height="313" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Double-clicking “CustOrdersDetail” brings up the “Add Function Import” dialog:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Untitled" border="0" alt="Untitled" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_thumb_1.png" width="307" height="349" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We click “Get Column Information” in order to see the metadata returned by the server about this stored procedure’s return columns. Then, we click on the “Create New Complex Type” button, and the designer automatically creates a new complex type that matches the shape of the data returned from the stored procedure:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Untitled" border="0" alt="Untitled" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_thumb_2.png" width="307" height="375" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;To make life more interesting (and realistic,) let’s rename some of the properties in the generated complex type: ProductName to Name, and UnitPrice to Price. To keep things running, we then need to fix the function import’s mappings to look like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Untitled" border="0" alt="Untitled" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_thumb_3.png" width="358" height="129" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Finally, to simulate some real-world churn, we change the stored procedure’s return shape: We’ll rename “UnitPrice” to “UnitPricing”, add a new column called “Foo”, and delete “Quantity”:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;ALTER&lt;/span&gt; &lt;span style="color: #0000ff"&gt;PROCEDURE&lt;/span&gt; CustOrdersDetail @OrderID &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;AS&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;SELECT&lt;/span&gt; ProductName,&lt;br /&gt;    UnitPricing=ROUND(Od.UnitPrice, 2),&lt;br /&gt;    Discount=&lt;span style="color: #0000ff"&gt;CONVERT&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;, Discount * 100),&lt;br /&gt;       Foo = &lt;span style="color: #006080"&gt;'!'&lt;/span&gt;, &lt;br /&gt;    ExtendedPrice=ROUND(&lt;span style="color: #0000ff"&gt;CONVERT&lt;/span&gt;(money, Quantity * (1 - Discount) * Od.UnitPrice), 2)&lt;br /&gt;&lt;span style="color: #0000ff"&gt;FROM&lt;/span&gt; Products P, [&lt;span style="color: #0000ff"&gt;Order&lt;/span&gt; Details] Od&lt;br /&gt;&lt;span style="color: #0000ff"&gt;WHERE&lt;/span&gt; Od.ProductID = P.ProductID &lt;span style="color: #0000ff"&gt;and&lt;/span&gt; Od.OrderID = @OrderID&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt; That done, we double click on the function import again, get column information, and this time, click on the “Update” button. The designer will now inspect the mappings, the existing complex type, and the new return shape, and produce these proposed changes to the complex type:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Untitled" border="0" alt="Untitled" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_thumb_4.png" width="375" height="123" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As you can see, “Foo” will be added, and “Quantity” will be deleted. In addition, the mappings are used to map “Name” to “ProductName” meaning no action will be taken for it. Finally, since “UnitPricing” is seen as new, “Price” will be deleted and “UnitPricing” will be put in its stead. Since we do not want this, we will rename the column in the function import’s mapping to “UnitPricing” and rerun the above process. This time we get:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Untitled" border="0" alt="Untitled" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/AutomaticGenerationofStoredProcedureRetu_AA47/Untitled_thumb_5.png" width="368" height="121" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Which is what we would want.&lt;/p&gt;

&lt;p&gt;In conclusion, the designer now exposes the Entity Framework’s new ability to return complex type instances from stored procedure. On top of this, it adds some features to make this capability easier to use and to iterate over. In future releases of Visual Studio, we will improve the iterative features and look into supporting batch imports of stored procedures, so that you will not need to import them one by one. We look forward to your feedback.&lt;/p&gt;

&lt;p&gt;Noam Ben-Ami
  &lt;br /&gt;Program Manager, Entity Designer&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9921549" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Visual+Studio+2010+Beta+2/default.aspx">Visual Studio 2010 Beta 2</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category></item><item><title>Foreign Key Relationships in the Entity Framework</title><link>http://blogs.msdn.com/adonet/archive/2009/11/06/foreign-key-relationships-in-the-entity-framework.aspx</link><pubDate>Fri, 06 Nov 2009 22:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9918854</guid><dc:creator>dpblogs</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9918854.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9918854</wfw:commentRss><description>&lt;p&gt;Last March &lt;a href="http://blogs.msdn.com/alexj" mce_href="http://blogs.msdn.com/alexj"&gt;Alex James&lt;/a&gt; posted to our design blog about &lt;a href="http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx"&gt;our plans for adding foreign keys to the entity framework&lt;/a&gt;. Since then we’ve pushed forward with implementing FK associations and properties and have included them in &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" mce_href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;Visual Studio 2010 Beta 2&lt;/a&gt;. This article offers a walkthrough of foreign key relationships in the EF and how they’re useful in VS2010 Beta2. For more information, the documentation and a number of blogs offer useful background about the logic behind adding EF foreign key relationships; here are a few links:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx"&gt;http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2008/10/27/foreign-keys-in-the-conceptual-and-object-models.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/10/27/foreign-keys-in-the-conceptual-and-object-models.aspx"&gt;http://blogs.msdn.com/efdesign/archive/2008/10/27/foreign-keys-in-the-conceptual-and-object-models.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee373856%28VS.100%29.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ee373856(VS.100).aspx"&gt;Defining and Managing Relationship MSDN documentation&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Walkthrough:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;We’re going to look at the designer experience, the EDMX model differences and a few coding examples. We’ll use this extremely simple database model:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_2.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_2.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb.png" style="border: 0px none ; display: inline;" title="Untitled" alt="Untitled" mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb.png" width="469" border="0" height="200"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Note the fact that the Posts table has a foreign key to the Blogs table.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Designer Experience&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Start by creating a new WPF application then add a new ADO.NET Entity Data Model item to it. Choose to generate the model from the database. Open the Tables portion of the treeview and check the Blogs and Posts tables. Note when choosing the tables with which to generate Entities “Include Foreign Key Columns in the Model” is checked by default. This means new models by default will use the new FK associations rather than Independent Associations. Independent Associations were previously the only type of association offered in the Entity Framework and still can be used. If you want just Independent Associations in your model, you’ll need to uncheck the Include FK Columns in the Model checkbox.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_4.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_4.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_1.png" style="border: 0px none ; display: inline;" title="Untitled" alt="Untitled" mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_1.png" width="461" border="0" height="409"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;After clicking Finish your model should look as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_6.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_6.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_2.png" style="border: 0px none ; display: inline;" title="Untitled" alt="Untitled" mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_2.png" width="403" border="0" height="278"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Double click the association and you’ll see the foreign key properties for the relationship:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_8.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_8.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_3.png" style="border: 0px none ; display: inline;" title="Untitled" alt="Untitled" mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_3.png" width="452" border="0" height="260"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Let’s leave this as is for now but note it’s possible to switch an existing Association between an FK or Independent Association type. In this case if you wanted to switch an Association to be Independent, you’d press the Delete button in the Referential Constraint dialog. After doing so you’d need to map the Independent Association appropriately and remove the BlogID property from the Post Entity. For now let’s move on without changing the association type.&lt;/p&gt;  &lt;p&gt;For comparison sake, add a new entity to the design surface from the toolbox. Once done, right click on the entity and choose Add-&amp;gt;Association:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_10.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_10.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_4.png" style="border: 0px none ; display: inline;" title="Untitled" alt="Untitled" mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ForeignKeyRelationshipsintheEntityFramew_C64A/Untitled_thumb_4.png" width="400" border="0" height="444"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Note that your association doesn’t have to be an FK association (association types can be mixed in the same model). Uncheck the ‘Add foreign key properties to the ‘Blog’ Entity’ check box then Click OK in the dialog. This will let us later look at the model differences between Independent and Foreign Key associations.&lt;/p&gt;  &lt;p&gt;So far we’ve: created a WPF project, added an EDM Data Model to it, reverse engineered our Blogs and Posts tables to the model, then added a third entity and created an Independent Association with it.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;XML model differences:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;We’re going to briefly diverge and look at some of the differences in the XML generated for the different types of associations in our simple model. If you don’t want to do this, feel free to skip to the next section.&lt;/p&gt;  &lt;p&gt;Right click on the EDMX file in your project and choose Open With-&amp;gt;XML Editor. This will close the design surface and open the contents of the EDMX file in the XML Editor.&lt;/p&gt;  &lt;p&gt;Scrolling down, the CSDL XML fragment for our Independent Association looks like this:&lt;/p&gt;  &lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;   &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Association&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Entity1Blog"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="BlogsModel.Entity1"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Role&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Entity1"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Multiplicity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="BlogsModel.Blog"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Role&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blog"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Multiplicity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="*"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Association&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;p&gt;It would also have an MSL XML fragment that tells EF how to traverse the relationship if we’d mapped the new entity &amp;amp; association to storage objects. Since we didn’t complete the mappings the fragment is missing.&lt;/p&gt;

&lt;p&gt;The CSDL XML fragment for our FK Associations looks like this:&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Association&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="FK_BlogPost"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Role&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogs"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="BlogsModel.Blog"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Multiplicity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;End&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Role&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Posts"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="BlogsModel.Post"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Multiplicity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="*"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ReferentialConstraint&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Principal&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Role&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogs"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;              &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;PropertyRef&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="BlogID"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Principal&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Dependent&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Role&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Posts"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;              &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;PropertyRef&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="BlogID"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Dependent&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;ReferentialConstraint&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Association&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;p&gt;Notice the ReferentialConstraint element and its contents. There is also no MSL XML fragment for the relationship.&lt;/p&gt;

&lt;p&gt;One other thing of interest to note is the Post EntityType has this fragment in the CSDL:&lt;/p&gt;

&lt;p&gt;&amp;lt;Property Name="BlogID" Type="Int32" Nullable="false" /&amp;gt;&lt;/p&gt;

&lt;p&gt;Having the BlogID property on the Post Entity will allow us to directly read &amp;amp; manipulate its value plus use it for data binding (no more need for partial classes with this exposed as a property).&lt;/p&gt;

&lt;p&gt;This divergence this tells us three things:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;EF is handling the two different types of Associations completely differently.&lt;/li&gt;

  &lt;li&gt;If you want to dig into an EDMX and tell what types of Associations you have you can (but looking at the XML can hurt your eyes J).&lt;/li&gt;

  &lt;li&gt;Foreign Key Associations add the parent ID key properties as properties on the child object. This is useful in a number of ways.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Coding experience&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Double click on the EDMX file in your project. After clicking Yes, this should reopen the EF Designer for your model. Delete Entity1 from the design surface. This should give you valid model with everything mapped (exactly what you had after running the Add-&amp;gt;New Item wizard).&lt;/p&gt;

&lt;p&gt;We’re going to run through a few scenarios of how to code against our model. To facilitate, add a button to your WPF form and double click it.&lt;/p&gt;

&lt;p&gt;Scenario 1: Adding new Blog and a new Post together by setting Navigation properties.&lt;/p&gt;

&lt;p&gt;Note this is what you used to do without FK Associations and is still the recommended way of adding two &lt;b&gt;new&lt;/b&gt; dependent objects together. We’ll talk about why in a few minutes. Inside the button event handler add the following code:&lt;/p&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (BlogsEntities ctx = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; BlogsEntities())&lt;br&gt;{&lt;br&gt;    Blog myBlog = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Blog { BlogID = 9, Name = &lt;span style="color: rgb(0, 96, 128);"&gt;"Tim's blog"&lt;/span&gt;, Owner = &lt;span style="color: rgb(0, 96, 128);"&gt;"Tim"&lt;/span&gt; };&lt;br&gt;    Post myPost = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Post { PostID = 102, Title = &lt;span style="color: rgb(0, 96, 128);"&gt;"Post Title"&lt;/span&gt;, PostContent = &lt;span style="color: rgb(0, 96, 128);"&gt;"TestContent"&lt;/span&gt;,&lt;br&gt;= DateTime.Now, ModifiedDate = DateTime.Now };&lt;br&gt;    &lt;span style="color: rgb(0, 128, 0);"&gt;//Nav properties will work immediately.&lt;/span&gt;&lt;br&gt;    myBlog.Posts.Add(myPost);&lt;br&gt;    ctx.Blogs.AddObject(myBlog);&lt;br&gt;    ctx.SaveChanges();&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;p&gt;This code opens a connection to the DB, creates a new blog object, creates a new post object, adds the post object to the blog object’s Posts collection, adds the new blog objects to the context, then saves the changes to the database. Note that as soon as we added the myPost object to the Posts collection of myBlog we could use the navigation properties to traverse between the objects.&lt;/p&gt;

&lt;p&gt;Scenario 2: Adding new Blog and a new Post together but set the Post BlogID FK property instead of adding to the myBlog Posts collection.&lt;/p&gt;

&lt;p&gt;Delete the code you just placed in the event handler and replace it with the following:&lt;/p&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (BlogsEntities ctx = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; BlogsEntities())&lt;br&gt;            {&lt;br&gt;                Blog myBlog = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Blog{BlogID = 11, Name = &lt;span style="color: rgb(0, 96, 128);"&gt;"Tim's blog"&lt;/span&gt;, Owner = &lt;span style="color: rgb(0, 96, 128);"&gt;"Tim"&lt;/span&gt;};&lt;br&gt;                Post myPost = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Post{PostID = 101,Title = &lt;span style="color: rgb(0, 96, 128);"&gt;"Post Title"&lt;/span&gt;, CreatedDate = DateTime.Now,  &lt;br&gt;                    ModifiedDate = DateTime.Now, PostContent=&lt;span style="color: rgb(0, 96, 128);"&gt;"Post Content"&lt;/span&gt;, BlogID = 11};&lt;br&gt;                ctx.Posts.AddObject(myPost);&lt;br&gt;                ctx.Blogs.AddObject (myBlog);&lt;br&gt;                ctx.SaveChanges();&lt;br&gt;            }&lt;br&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;p&gt;Note that the navigation properties on the two new objects won’t map to each other until after SaveChanges is called. This is because the context doesn’t know about the parent object yet.&lt;/p&gt;

&lt;p&gt;Scenario 3: Adding a new post to an already existing blog.&lt;/p&gt;

&lt;p&gt;Replace the code in the event handler with the following:&lt;/p&gt;

&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;
  &lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (BlogsEntities ctx = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; BlogsEntities())&lt;br&gt;            {&lt;br&gt;                Post myPost = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Post {PostID = 102, Title = &lt;span style="color: rgb(0, 96, 128);"&gt;"Post Title"&lt;/span&gt;, CreatedDate = &lt;br&gt;DateTime.Now, ModifiedDate =DateTime.Now, PostContent = &lt;span style="color: rgb(0, 96, 128);"&gt;"Post Content"&lt;/span&gt;, BlogID = 11};&lt;br&gt;                &lt;span style="color: rgb(0, 128, 0);"&gt;//Nav properties will work immediately b/c the Blog object already exists&lt;/span&gt;&lt;br&gt;                ctx.Posts.AddObject(myPost);&lt;br&gt;                ctx.SaveChanges();&lt;br&gt;            }&lt;br&gt;&lt;/pre&gt;

  &lt;br&gt;&lt;/div&gt;

&lt;p&gt;Note we never loaded the Blog object into memory. We knew BlogID 11 was a valid ID and set the post.BlogID property directly. Note also, the navigation property for myPost.Blog will work immediately after setting the FK property because the Blog object already exists in the context. Being able to set the property directly enables some previously difficult data binding scenarios as well as can make some coding experiences easier.&lt;/p&gt;

&lt;p&gt;These three coding examples show different ways of creating new objects and setting up their relationships using navigation properties and FK associations.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;In .NET 4.0 we’ve added support for FK Properties and FK Associations to the Entity Framework. It’s still possible to use Independent Associations and the two can be mixed in models. We’re excited to offer FK Associations because they simplify many common Entity Framework coding tasks. Hopefully this walkthrough has given you a feel for how you can use FK Associations and Properties.&lt;/p&gt;

&lt;p&gt;As always we'd love to hear your thoughts.&lt;/p&gt;

&lt;p&gt;Thanks,
  &lt;br&gt;Tim Laverty, Program Manager&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9918854" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Visual+Studio+2010+Beta+2/default.aspx">Visual Studio 2010 Beta 2</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category></item><item><title>Model First with the Entity Framework 4</title><link>http://blogs.msdn.com/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx</link><pubDate>Thu, 05 Nov 2009 17:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9918101</guid><dc:creator>dpblogs</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9918101.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9918101</wfw:commentRss><description>&lt;P&gt;In a &lt;A href="http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-model-first-in-the-entity-framework-4-0.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-model-first-in-the-entity-framework-4-0.aspx"&gt;previous post&lt;/A&gt;, we walked through the designer’s “out of the box” database schema generation experience. In this post, we show how some new designer features in VS2010 Beta 2 integrate with this capability, then we pop the hood and show how easy it is to replace or extend parts of the generation system.&lt;/P&gt;
&lt;P&gt;We will begin with a simple model that contains two newly supported constructs: Employee.EmployerId is a foreign key that references Company.Id, and Person.Address is a complex type.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_2.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb.png" width=516 height=317 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;To show the details of the model, we also include the EDM’s XML:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum1&gt;   1:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Schema&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;xmlns:annotation&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://schemas.microsoft.com/ado/2009/02/edm/annotation"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Namespace&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Alias&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Self"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://schemas.microsoft.com/ado/2008/09/edm"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum2&gt;   2:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityContainer&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModelContainer"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;annotation:LazyLoadingEnabled&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum3&gt;   3:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntitySet&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Persons"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;EntityType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.Person"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum4&gt;   4:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntitySet&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Companies"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;EntityType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.Company"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum5&gt;   5:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;AssociationSet&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CompanyEmployee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Association&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.CompanyEmployee"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum6&gt;   6:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Role&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Company"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;EntitySet&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Companies"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum7&gt;   7:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Role&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Employee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;EntitySet&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Persons"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum8&gt;   8:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;AssociationSet&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum9&gt;   9:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityContainer&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum10&gt;  10:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityType&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Person"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum11&gt;  11:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum12&gt;  12:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;PropertyRef&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Id"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum13&gt;  13:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum14&gt;  14:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Int32"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Id"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;annotation:StoreGeneratedPattern&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Identity"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum15&gt;  15:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="FirstName"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum16&gt;  16:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="LastName"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum17&gt;  17:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Address"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.Address"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum18&gt;  18:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum19&gt;  19:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityType&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Employee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;BaseType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.Person"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum20&gt;  20:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Title"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum21&gt;  21:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;NavigationProperty&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Company"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.CompanyEmployee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;FromRole&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Employee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ToRole&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Company"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum22&gt;  22:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Int32"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="EmployerId"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum23&gt;  23:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum24&gt;  24:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityType&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Company"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum25&gt;  25:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum26&gt;  26:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;PropertyRef&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Id"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum27&gt;  27:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Key&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum28&gt;  28:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Int32"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Id"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;annotation:StoreGeneratedPattern&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Identity"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum29&gt;  29:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Name"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum30&gt;  30:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Address"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum31&gt;  31:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;NavigationProperty&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Employees"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.CompanyEmployee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;FromRole&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Company"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ToRole&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Employee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum32&gt;  32:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;EntityType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum33&gt;  33:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ComplexType&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Address"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum34&gt;  34:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Street"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Unicode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;MaxLength&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="250"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;FixedLength&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum35&gt;  35:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="City"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Unicode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum36&gt;  36:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Zip"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;FixedLength&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;MaxLength&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="5"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Unicode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum37&gt;  37:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="State"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;FixedLength&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;MaxLength&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="100"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Unicode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum38&gt;  38:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Property&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="String"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Country"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Unicode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum39&gt;  39:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ComplexType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum40&gt;  40:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Association&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CompanyEmployee"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum41&gt;  41:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.Company"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Role&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Company"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Multiplicity&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="1"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum42&gt;  42:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="SimpleModel.Employee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Role&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Employee"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Multiplicity&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="*"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum43&gt;  43:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ReferentialConstraint&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum44&gt;  44:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Principal&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Role&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Company"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum45&gt;  45:&lt;/SPAN&gt;               &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;PropertyRef&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Id"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum46&gt;  46:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Principal&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum47&gt;  47:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Dependent&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Role&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Employee"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum48&gt;  48:&lt;/SPAN&gt;               &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;PropertyRef&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="EmployerId"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum49&gt;  49:&lt;/SPAN&gt;             &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Dependent&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum50&gt;  50:&lt;/SPAN&gt;           &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;ReferentialConstraint&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum51&gt;  51:&lt;/SPAN&gt;         &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Association&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #606060" id=lnum52&gt;  52:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Schema&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Note the ReferentialConstraint element above, which defines the foreign key, and the ComplexType element that defines the Address type.&lt;/P&gt;
&lt;P&gt;When we run the database generation script against this model, we get the following table definitions:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;SPAN style="COLOR: #008000"&gt;-- Creating table 'Persons'&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;TABLE&lt;/SPAN&gt; [dbo].[Persons] (&lt;BR&gt;    [Id] &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;IDENTITY&lt;/SPAN&gt;(1,1) &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [FirstName] nvarchar(&lt;SPAN style="COLOR: #0000ff"&gt;max&lt;/SPAN&gt;)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [LastName] nvarchar(&lt;SPAN style="COLOR: #0000ff"&gt;max&lt;/SPAN&gt;)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Address_Street] nvarchar(250)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Address_City] nvarchar(&lt;SPAN style="COLOR: #0000ff"&gt;max&lt;/SPAN&gt;)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Address_Zip] &lt;SPAN style="COLOR: #0000ff"&gt;char&lt;/SPAN&gt;(5)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Address_State] nvarchar(100)  &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Address_Country] &lt;SPAN style="COLOR: #0000ff"&gt;varchar&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;max&lt;/SPAN&gt;)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;&lt;BR&gt;);&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;GO&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;-- Creating table 'Companies'&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;TABLE&lt;/SPAN&gt; [dbo].[Companies] (&lt;BR&gt;    [Id] &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;IDENTITY&lt;/SPAN&gt;(1,1) &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Name] nvarchar(&lt;SPAN style="COLOR: #0000ff"&gt;max&lt;/SPAN&gt;)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Address] nvarchar(&lt;SPAN style="COLOR: #0000ff"&gt;max&lt;/SPAN&gt;)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;&lt;BR&gt;);&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;GO&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #008000"&gt;-- Creating table 'Persons_Employee'&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;TABLE&lt;/SPAN&gt; [dbo].[Persons_Employee] (&lt;BR&gt;    [Title] nvarchar(&lt;SPAN style="COLOR: #0000ff"&gt;max&lt;/SPAN&gt;)  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [EmployerId] &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;,&lt;BR&gt;    [Id] &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;NULL&lt;/SPAN&gt;&lt;BR&gt;);&lt;BR&gt;&lt;SPAN style="COLOR: #0000ff"&gt;GO&lt;/SPAN&gt;&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;A few things to note:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The complex type was “rolled-up” into its owning type’s table, and the name of the complex property was appended to the name of the complex type properties, e.g. “Address_State”.&lt;/LI&gt;
&lt;LI&gt;The foreign key property “EmployerId” was pulled through into the model, rather than a “hidden” foreign key being generated, as would have been the case for a relationship that did not specify a referential constraint. Another blog post will go into referential constraints in more detail.&lt;/LI&gt;
&lt;LI&gt;The name of a table that stores instances of subtypes is composed of the name of the subtype’s set to which we append the name of the type, e.g. “Persons_Employee”.&lt;/LI&gt;
&lt;LI&gt;We’ve set the Address.Zip property to be a fixed length non-unicode string, and so it is generated as a char(5).&lt;/LI&gt;
&lt;LI&gt;If you do not specify unicode, the default is true. If you do not specify fixed length, the default is false. If you do not specify max length, the default is “max”.&lt;/LI&gt;
&lt;LI&gt;Property Persons.Id’s StoreGeneratedPattern property is set to “Identity”, which makes it an IDENTITY(1,1) in the database.&lt;/LI&gt;
&lt;LI&gt;Not shown in the above script are the key and constraint definitions, which are similar to those shown in the previous post.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Now, let’s take a look at how model first actually works, so we can see how to change what it does. Click on any empty area in the designer surface to see the top-level properties of the model:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_4.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_4.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_1.png" width=301 height=362 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Of interest to us are two of the three “Database Script Generation” properties:&lt;/P&gt;
&lt;P&gt;&lt;I&gt;Database Generation Workflow&lt;/I&gt; – Controls the overall process by which the conceptual model is translated into a database script. The default workflow is “TablePerTypeStrategy.xaml”.&lt;/P&gt;
&lt;P&gt;&lt;I&gt;DDL Generation Template&lt;/I&gt; – Is called by the default database generation workflow to transform the generated database model to DDL. More on this below.&lt;/P&gt;
&lt;P&gt;First, let’s take a look at TablePerTypeStrategy.xaml – it is located in &lt;I&gt;Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen&lt;/I&gt;. If we open this file in Visual Studio, we see that it is a Workflow Foundation (WF) workflow:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_6.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_6.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_2.png" width=244 height=233 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The first activity, “CsdlToSsdlAndMslActivity” generates the store model (SSDL) for the EDM, and then generates the mappings (MSL) that connect the two. It has the following properties:&lt;/P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_8.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_8.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_3.png" width=502 height=145 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_3.png"&gt;&lt;/A&gt; 
&lt;P&gt;The “MslOutputGeneratorType” specifies a class that generates MSL based on a table-per-type mapping strategy. The “OuputGeneratorType” generates SSDL. Rather than replacing this activity and all of the plumbing it provides, you can replace these two classes with your own if you want to change the mapping strategy or otherwise alter the system. In future posts, we will provide examples and more details on the specifics of these classes. You can also replace this entire activity with your own activity that fills the MslOutput and SsdlOutput parameters using any mechanism you wish.&lt;/P&gt;
&lt;P&gt;The second activity, “SsdlToDdlActivity” generates DDL from the store model, and it does this by using a &lt;A href="http://msdn.microsoft.com/en-us/library/bb126445.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb126445.aspx"&gt;T4 template&lt;/A&gt;, which makes for very easy customization. In the same folder that TablePerTypeStrategy.xaml is installed, there is also SSDLToSQL10.tt which generates TSQL DDL. Templates for supporting other database platforms will become available in the future from Entity Framework provider writers. T4 templates are simple text files whose intent is to transform some sets of inputs, in this case, SSDL, to some output, DDL in this case. A full description of the template is outside the scope of this post, but we’ll take a brief look at one section of the template, the one that generates the table definitions. To help with readability, we have bolded those parts of the script that generate DDL:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;BR&gt;-- --------------------------------------------------&lt;BR&gt;-- Creating all tables&lt;BR&gt;-- --------------------------------------------------&lt;BR&gt;&lt;BR&gt;&amp;lt;#&lt;BR&gt;    &lt;SPAN class=kwrd&gt;foreach&lt;/SPAN&gt; (EntitySet entitySet &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; Store.GetAllEntitySets())&lt;BR&gt;    {&lt;BR&gt;        &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; schemaName = Id(entitySet.GetSchemaName());&lt;BR&gt;        &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; tableName = Id(entitySet.GetTableName());&lt;BR&gt;#&amp;gt;&lt;BR&gt;-- Creating table &lt;SPAN class=str&gt;'&amp;lt;#=tableName#&amp;gt;'&lt;/SPAN&gt;&lt;BR&gt;CREATE TABLE &amp;lt;# &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (!IsSQLCE) {#&amp;gt;[&amp;lt;#=schemaName#&amp;gt;].&amp;lt;#}#&amp;gt;[&amp;lt;#=tableName#&amp;gt;] (&lt;BR&gt;&amp;lt;#&lt;BR&gt;        &lt;SPAN class=kwrd&gt;for&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; p = 0; p &amp;lt; entitySet.ElementType.Properties.Count; p++)&lt;BR&gt;        {&lt;BR&gt;            EdmProperty prop = entitySet.ElementType.Properties[p];&lt;BR&gt;#&amp;gt;&lt;BR&gt;    [&amp;lt;#=Id(prop.Name)#&amp;gt;] &amp;lt;#=prop.ToStoreType()#&amp;gt; &lt;BR&gt;&amp;lt;#=WriteIdentity(prop, targetVersion)#&amp;gt; &amp;lt;#=WriteNullable(prop.Nullable)#&amp;gt;&lt;BR&gt;&amp;lt;#=(p &amp;lt; entitySet.ElementType.Properties.Count - 1) ? &lt;SPAN class=str&gt;","&lt;/SPAN&gt; : &lt;SPAN class=str&gt;""&lt;/SPAN&gt;#&amp;gt;&lt;BR&gt;&amp;lt;#&lt;BR&gt;        }&lt;BR&gt;#&amp;gt;&lt;BR&gt;);&lt;BR&gt;GO&lt;BR&gt;&amp;lt;# &lt;BR&gt;    } &lt;BR&gt;#&amp;gt;&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;As you can see, the template iterates over the objects in the SSDL and the translation is fairly straightforward.&lt;/P&gt;
&lt;P&gt;The experience when additional templates and workflows are installed is tremendously improved relative to Visual Studio 2010 Beta1. To demonstrate this, copy and paste TablePerTypeStrategy.xaml and rename it to CustomStrategy.xaml. Copy and paste SSDLToSQL10.tt and rename it SSDLToCustomDDL.tt. When we switch back to the designer and look at the designer property sheet, we will see these new files appear in the drop downs for the workflow and template properties:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_10.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_10.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_4.png" width=348 height=86 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;And:&lt;/P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_12.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_12.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_5.png" width=349 height=109 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_5.png"&gt;&lt;/A&gt; 
&lt;P&gt;So now you can mix and match two different strategies with two different DDL generators, for example, you could mix and match a table-per-hierarchy strategy with either a SQL or a Firebird database schema template.&lt;/P&gt;
&lt;P&gt;But there is a problem: Installing templates and workflows in the Visual Studio path is often neither advisable nor possible. So we’ve provided two additional install locations. The first is &lt;I&gt;%localappdata%\Microsoft\[AppId]\10.0\Extensions\Microsoft\Entity Framework Tools\DBGen&lt;/I&gt; where [AppId] depends on your Visual Studio SKU, for example:&lt;/P&gt;
&lt;P&gt;&lt;I&gt;D:\documents and settings\sqlcl02\Local Settings\Application Data\Microsoft\VisualStudio\10.0\Extensions\Microsoft\Entity Framework Tools\DBGen.&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Copy the same files to this folder and rename them to CustomUserStrategy.xaml and SSDLToCustomUserDDL.tt and they will immediately show up:&lt;/P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_14.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_14.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_6.png" width=340 height=91 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_6.png"&gt;&lt;/A&gt; 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_16.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_16.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_7.png" width=342 height=121 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_7.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Finally, if you want a custom workflow or template specifically for your project, copy the template or workflow to your project and type in the path. For example:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_18.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_18.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=Untitled border=0 alt=Untitled src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_8.png" width=374 height=73 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/ModelFirstwiththeEntityFramework4_8ABE/Untitled_thumb_8.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Make sure that the (VS) or (User) postfixes are not in the path.&lt;/P&gt;
&lt;P&gt;In summary, it is very easy now to mix and much strategies and target database DDL formats, as well as to install your own custom workflows and templates. In a future post, we will walk through examples of custom strategies and templates.&lt;/P&gt;
&lt;P&gt;Noam Ben-Ami &lt;BR&gt;Program Manager, &lt;BR&gt;Entity Designer&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9918101" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Visual+Studio+2010+Beta+2/default.aspx">Visual Studio 2010 Beta 2</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category></item><item><title>ADO.Net Entity Framework Feature Community Technology Preview Released!</title><link>http://blogs.msdn.com/adonet/archive/2009/11/04/ado-net-entity-framework-community-technology-preview-released.aspx</link><pubDate>Wed, 04 Nov 2009 23:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9917632</guid><dc:creator>dpblogs</dc:creator><slash:comments>18</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9917632.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9917632</wfw:commentRss><description>&lt;P&gt;We’ve released an &lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=13fdfce4-7f92-438f-8058-b5b4041d0f01" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=13fdfce4-7f92-438f-8058-b5b4041d0f01"&gt;update of the Entity Framework Feature CTP&lt;/A&gt;!&amp;nbsp; The updated CTP includes many requested improvements and added features we’ve gathered from the community since the release of our first CTP and supports installation with &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" mce_href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;Visual Studio 2010 Beta 2&lt;/A&gt; as well.&amp;nbsp; Some of the improvements and added features added since the last CTP include:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Enhancements to Code Only, including-&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Fine Grained Control over model&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Specify Navigation Property Inverses&lt;/LI&gt;
&lt;LI&gt;Specify Property Facets&lt;/LI&gt;
&lt;LI&gt;Complex Types&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Customizable Mappings &lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Change Table Name, Column Names&lt;/LI&gt;
&lt;LI&gt;Specify Custom Inheritance Strategy &lt;/LI&gt;
&lt;LI&gt;Entity Splitting&lt;/LI&gt;
&lt;LI&gt;Join Table Mapping&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;LI&gt;The Self-Tracking Entities template, allowing code generation of EF entities that facilitate ease of use in WCF/N-Tier scenarios-&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Foreign Key associations: Self-Tracking Entities can take advantage of the Foreign Keys in the Model feature added in .NET 4.0 Beta 2 and can contain both navigation properties and Foreign Key properties for the same association. Fix-up logic has been tidied up to be aware of FKs. &lt;/LI&gt;
&lt;LI&gt;Support for Silverlight 3: Generated entity types can be compiled to target Silverlight 3 and can be used in combination with Silverlight-enabled WCF services.&lt;/LI&gt;
&lt;LI&gt;Databinding support: Generated entity types now implement INotifyPropertyChanged and use ObservableCollections allowing them to work better with WPF and Silverlight databinding. &lt;/LI&gt;
&lt;LI&gt;Richer concurrency control support: Self-Tracking Entities now support the same variations for optimistic concurrency control as the Entity Framework. Original values are preserved for all required properties according to their concurrency mode in the Entity Data Model.&lt;/LI&gt;
&lt;LI&gt;Improved independent association support: The approach for managing entities with dangling references has been reengineered to avoid unnecessary database round-trips.&lt;/LI&gt;
&lt;LI&gt;New and improved methods: AcceptChanges, StartTracking, StopTracking where added and the existing MarkAsX methods are now extension methods.&lt;/LI&gt;
&lt;LI&gt;Generated code improvements and refactoring: The ApplyChanges implementation has been moved to the Context template so the template has no binary dependencies besides Entity Framework. Generated code for entity types have been refactored. &lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P&gt;Over the next few weeks we’ll be posting walkthroughs that dive deeper into each feature.&amp;nbsp; We also have a few features we plan to release in CTP format in the next few months including an updated POCO code gen template.&amp;nbsp; Your comments and feedback are most welcome; please give us your comments here, our &lt;A href="http://blogs.msdn.com/efdesign/" mce_href="http://blogs.msdn.com/efdesign/"&gt;design blog&lt;/A&gt;, through Connect or through the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/threads" mce_href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/threads"&gt;ADO.NET Entity Framework pre-release forums&lt;/A&gt;.&amp;nbsp; Please stay tuned for more news!&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;The Entity Framework Team&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9917632" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/What_2700_s+New/default.aspx">What's New</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framwork+Feature+CTP2+for+.NET+4.0/default.aspx">Entity Framwork Feature CTP2 for .NET 4.0</category></item><item><title>Upcoming ADO.Net Entity Framework Feature Community Technology Preview for Visual Studio 2010 Beta 2</title><link>http://blogs.msdn.com/adonet/archive/2009/10/26/upcoming-ado-net-entity-framework-feature-community-technology-preview-for-visual-studio-2010-beta-2.aspx</link><pubDate>Tue, 27 Oct 2009 00:42:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9913269</guid><dc:creator>dpblogs</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9913269.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9913269</wfw:commentRss><description>&lt;p&gt;Just a quick note to let everyone know we’re actively working on an updated Feature CTP for Visual Studio 2010 Beta 2.&amp;#160; As soon as the bits are ready we’ll release and post here again.&amp;#160; Currently the plan is to include some great new enhancements for Code Only and Self-Tracking Entities with the bits.&lt;/p&gt;  &lt;p&gt;Please be patient &amp;amp; stay tuned!&lt;/p&gt;  &lt;p&gt;Thanks!   &lt;br /&gt;The Entity Framework Team&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9913269" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Feature+CTP1+for+.NET+4.0/default.aspx">Entity Framework Feature CTP1 for .NET 4.0</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Visual+Studio+2010+Beta+2/default.aspx">Visual Studio 2010 Beta 2</category><category domain="http://blogs.msdn.com/adonet/archive/tags/What_2700_s+New/default.aspx">What's New</category></item><item><title>New features in Entity Framework impacting providers</title><link>http://blogs.msdn.com/adonet/archive/2009/10/22/new-features-in-entity-framework-impacting-providers.aspx</link><pubDate>Thu, 22 Oct 2009 19:31:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9911626</guid><dc:creator>dpblogs</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9911626.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9911626</wfw:commentRss><description>&lt;p&gt;Providers for Entity Framework 3.5 will work unmodified against Entity Framework 4.0. Also, most of the features and improvements introduced in Entity Framework 4.0 will just work against an Entity Framework 3.5 provider. However, there are several features that require provider changes to be enabled. Below is a list of these features along with short description of the changes required to enable them.&lt;/p&gt;  &lt;h4&gt;New features in Entity Framework Runtime impacting providers&lt;/h4&gt;  &lt;h5&gt;New EDM (Canonical) Functions &lt;/h5&gt;  &lt;p&gt;In Entity Framework 3.5 there is a set of EDM (canonical) functions, which are defined by the Entity Framework and should be supported by all store providers. In Entity Framework 4.0 we are expanding that set by adding a number of new string, aggregate, mathematical, and date/time functions. Providers would need to add support for these new functions, listed below.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Date/Time functions&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;CreateDateTime(year, month, day, hour, minute, second)&lt;/p&gt;  &lt;p&gt;CreateDateTimeOffset(year, month, day, hour, minute, second, tzoffset)&lt;/p&gt;  &lt;p&gt;CreateTime(hour, minute, second)&lt;/p&gt;  &lt;p&gt;DayOfYear(expression)&lt;/p&gt;  &lt;p&gt;TruncateTime(expression)&lt;/p&gt;  &lt;p&gt;AddYears(expression, number)&lt;/p&gt;  &lt;p&gt;AddMonths(expression, number) &lt;/p&gt;  &lt;p&gt;AddDays(expression, number)&lt;/p&gt;  &lt;p&gt;AddHours(expression, number)&lt;/p&gt;  &lt;p&gt;AddMinutes(expression, number)&lt;/p&gt;  &lt;p&gt;AddSeconds(expression, number)&lt;/p&gt;  &lt;p&gt;AddMilliseconds(expression, number)&lt;/p&gt;  &lt;p&gt;AddMicroseconds(expression, number)&lt;/p&gt;  &lt;p&gt;AddNanoseconds(expression, number)&lt;/p&gt;  &lt;p&gt;DiffYears(startExpression, endExpression) &lt;/p&gt;  &lt;p&gt;DiffMonths(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;DiffDays(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;DiffHours(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;DiffMinutes(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;DiffSeconds(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;DiffMilliseconds(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;DiffMicroseconds(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;DiffNanoseconds(startExpression, endExpression)&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Math Functions&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Power(value, exponent)&lt;/p&gt;  &lt;p&gt;Truncate(value, digits)&lt;/p&gt;  &lt;p&gt;Round(value, digits)&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Aggregate functions&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;StDevP(expression)&lt;/p&gt;  &lt;p&gt;Var (expression)&lt;/p&gt;  &lt;p&gt;VarP (expression)&lt;/p&gt;  &lt;p&gt;&lt;b&gt;String functions&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Contains(string, target)&lt;/p&gt;  &lt;p&gt;StartsWith(string, target)&lt;/p&gt;  &lt;p&gt;EndsWith(string, target)&lt;/p&gt;  &lt;h5&gt;Exposing provider functions in LINQ To Entities ()&lt;/h5&gt;  &lt;p&gt;Entity Framework 3.5 customers preferring to write their queries using LINQ often hit a limitation on the range of functions and query patterns supported in LINQ to Entities. To address that issue, we are providing an extensibility mechanism that can be used to map CLR methods to provider and to EDM functions. &lt;/p&gt;  &lt;p&gt;The basis of the extensibility mechanism is a new method-level attribute that carry function mapping information. Here is the basic signature of the attribute’s constructor: &lt;/p&gt;  &lt;p&gt;public EdmFunctionAttribute(string namespaceName, string functionName) &lt;/p&gt;  &lt;p&gt;The namespaceName parameter indicates the namespace for the function in metadata (i.e. “EDM” or “SQLSERVER”, or other store provider namespace). The functionName parameter takes the name of the function itself.&lt;/p&gt;  &lt;p&gt;We encourage providers to expose classes that represent their store functions, so that when their provider is used they are readily available via LINQ to Entities. Here are some recommendations with regards to which functions to expose and how:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Which functions to expose?&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;These that provide functionality not already provided via the base class library functions supported by LINQ to Entities or the EDM functions.&lt;b&gt;&lt;/b&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Overloads – Provide enough for pleasant user experience &lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Specify the scalar arguments and return types as nullable &lt;/li&gt;    &lt;li&gt;Provide overloads for nullable and non-nullable collection element for collection arguments &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Proxies Implementation &lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Trigger direct evaluation over the input ObjectQuery for methods taking collection arguments &lt;/li&gt;    &lt;li&gt;Throw NotSupportedException in all other cases &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Example:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;   &lt;pre id="codeSnippet" class="csharpcode"&gt;[EdmFunction(“SampleSqlServer&lt;span class="str"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;CHECKSUM_AGG&lt;span class="str"&gt;&amp;quot;)] &lt;br /&gt;        public static Int32? ChecksumAggregate( IEnumerable&amp;lt;Int32&amp;gt; arg)  { &lt;br /&gt;            ObjectQuery&amp;lt;Int32&amp;gt; objectQuerySource = arg as ObjectQuery&amp;lt;Int32&amp;gt;; &lt;br /&gt;            if (objectQuerySource != null)  { &lt;br /&gt;                return ((IQueryable)objectQuerySource).Provider&lt;br /&gt;                      .Execute&amp;lt;Int32?&amp;gt;(Expression.Call((MethodInfo)MethodInfo&lt;br /&gt;                        .GetCurrentMethod(),Expression.Constant(arg))); &lt;br /&gt;            } &lt;br /&gt;     throw new NotSupportedException(&amp;quot;&lt;/span&gt;This function can only be invoked from LINQ &lt;br /&gt;                            to Entities.&lt;span class="str"&gt;&amp;quot;); &lt;br /&gt;        } &lt;br /&gt;         [EdmFunction(“SampleSqlServer&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;CHECKSUM_AGG&amp;quot;&lt;/span&gt;)]&lt;br /&gt;         &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Int32? ChecksumAggregate( IEnumerable&amp;lt;Int32?&amp;gt; arg)  { &lt;br /&gt;        { …. } &lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h5&gt;Translating String.StartsWith, String.EndsWith and String.Contains to LIKE in LINQ to Entities &lt;/h5&gt;

&lt;p&gt;In Entity Framework 3.5, in LINQ to Entities we provided support for the String.StartsWith, String.EndsWith and String.Contains and we translated them to canonical functions in the following way:&lt;/p&gt;

&lt;p&gt;Boolean String.Contains(String value) -&amp;gt; IndexOf(this, value) &amp;gt; 0&lt;/p&gt;

&lt;p&gt;Boolean String.EndsWith(String value) -&amp;gt; Right(this, length(value)) = value&lt;/p&gt;

&lt;p&gt;Boolean String.StartsWith(String value) -&amp;gt; IndexOf(this, value) = 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;

&lt;p&gt;However, due to the fact that these translations result in inability to utilize indexes on the tested string on some providers and that users found the resulting SQL more difficult to read, we are providing an option to translate these into DbLikeExpression, i.e:&lt;/p&gt;

&lt;p&gt;Boolean String.Contains(String value) -&amp;gt; DbLikeExpression(this, ‘%’ + value’ + ‘%’, escapeCharacter)&lt;/p&gt;

&lt;p&gt;Boolean String.EndsWith(String value) -&amp;gt; DbLikeExpression(this, ‘%’ + value’, escapeCharacter)&lt;/p&gt;

&lt;p&gt;Boolean String.StartsWith(String value) -&amp;gt; DbLikeExpression(this, value’ + ‘%’’, escapeCharacter)&lt;/p&gt;

&lt;p&gt;Here, value’ is the equivalent of value but with the wildcard characters and the escape character escaped, and escapeCharacter is the escape character. This translation only happens if value is a constant or a parameter.&amp;#160; &lt;/p&gt;

&lt;p&gt;Because different providers may have different wildcard characters, in order for this translation to happen provider writers need to override and provide implementations of the following methods that have been introduced in DbProviderManifest:&lt;/p&gt;

&lt;p&gt;public virtual bool SupportsEscapingLikeArgument(out char escapeCharacter)&lt;/p&gt;

&lt;p&gt;and &lt;/p&gt;

&lt;p&gt;public virtual string EscapeLikeArgument(string argument)&lt;/p&gt;

&lt;p&gt;The default implementation of SupportsEscapingLikeArgument returns false, thus if provider writers choose to not override these methods, they will still continue to get the old translations of these functions.&lt;/p&gt;

&lt;p&gt;Please note that this feature is not any public release yet, but it will be available in .NET 4.0.&lt;/p&gt;

&lt;h4&gt;New Features in Entity Designer Impacting Providers&lt;/h4&gt;

&lt;h5&gt;Model First &lt;/h5&gt;

&lt;p&gt;In Visual Studio 2010 the designer can generate mappings, storage model, and database DDL from a conceptual model. This feature is called “Model First.” In order to make this feature highly customizable, it is implemented using a Workflow Foundation (WF) workflow that users can replace. The workflow contains two activities: One which generates MSL and SSDL, and another which generates DDL.&lt;/p&gt;

&lt;p&gt;DDL generation is done by a T4 template which processes the SSDL generated by the previous workflow activity. Providers who wish to allow users to generate DDL for databases other than SQL Server will need to install a T4 DDL generation template in:&lt;/p&gt;

&lt;p&gt;%localappdata%\Microsoft\[AppId]\10.0\Extensions\Microsoft\Entity Framework Tools\DBGen&lt;/p&gt;

&lt;p&gt;Where [AppId] signifies either VisualStudio, VBExpress, VCSExpress, or VNSExpress depending on what SKU the user is using at the moment. Note that when searching for templates, the Entity Framework Designer does not do recursive searches.&amp;#160; &lt;br /&gt;Templates from this path have “(User)” post-pended to their name.&lt;/p&gt;

&lt;p&gt;For reference, built-in templates are installed in:&lt;/p&gt;

&lt;p&gt;%programFiles%\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen&lt;/p&gt;

&lt;p&gt;Templates from this path have “(VS)” post-pended to their name.&lt;/p&gt;

&lt;p&gt;Here is a screenshot. In this case, a template called “CustomDDL.tt” was added to the “(User)” path referenced above. (In the case of this specific machine, that path was D:\Documents and Settings\SQLCL02\Local Settings\Application Data\Microsoft\VisualStudio\10.0\Extensions\Microsoft\Entity Framework Tools\DBGen)&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/NewfeaturesinEntityFrameworkimpactingpro_C064/blog1_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="blog1" border="0" alt="blog1" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/NewfeaturesinEntityFrameworkimpactingpro_C064/blog1_thumb.png" width="392" height="125" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The same rules also apply to workflows. In this screenshot, we added a workflow called “CustomStrategy.xaml” to the “(User)” directory:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/NewfeaturesinEntityFrameworkimpactingpro_C064/blog1_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="blog1" border="0" alt="blog1" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/NewfeaturesinEntityFrameworkimpactingpro_C064/blog1_thumb_1.png" width="427" height="94" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In both cases, there is no need to restart VS, as the templates and workflows show up immediately.&lt;/p&gt;

&lt;p&gt;Please note that this feature is not any public release yet, but it will be available in Visual Studio 2010.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

&lt;p&gt;Kati Iceva
  &lt;br /&gt;Software Development Engineer, Entity Framework&lt;/p&gt;

&lt;p&gt;Noam Ben-Ami
  &lt;br /&gt;Program Manager, Entity Designer&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9911626" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Providers/default.aspx">Providers</category></item><item><title>VS2010 and .NET Framework 4 Beta 2 Announced!</title><link>http://blogs.msdn.com/adonet/archive/2009/10/19/vs2010-and-net-framework-beta-2-announced.aspx</link><pubDate>Tue, 20 Oct 2009 00:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9909581</guid><dc:creator>dpblogs</dc:creator><slash:comments>21</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9909581.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9909581</wfw:commentRss><description>&lt;P&gt;Visual Studio 2010 and the .NET Framework 4 Beta 2 are now available for &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" mce_href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;download by MSDN subscribers&lt;/A&gt; and will available to the rest of the world on Wednesday. Beta 2 as well the VS2010 Launch date of March 22, 2010 were announced this morning on &lt;A href="http://blogs.msdn.com/somasegar/archive/2009/10/19/announcing-visual-studio-2010-and-net-fx-4-beta-2.aspx" mce_href="http://blogs.msdn.com/somasegar/archive/2009/10/19/announcing-visual-studio-2010-and-net-fx-4-beta-2.aspx"&gt;Soma’s blog&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Included in Beta 2 are some great new features and updates for the Entity Framework 4 and ADO.NET Data Services 4. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Entity Framework 4 Beta 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In addition to all of the new EF 4 features that were included in Beta 1, Beta 2 also includes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Foreign Keys:&lt;/STRONG&gt; EF 4 now includes a new type of associations (Foreign Key Associations) that allow you to have Foreign Key properties on your entities. Foreign Key Associations simplify some key scenarios such as Data binding and can be included or excluded when using the model creation and update wizards. Independent Associations supported in .NET 3.5 remain as is, but Foreign Key Associations become the default type of association going forward. Referential integrity constraints can now be created from the designer. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Improvements to POCO Support: &lt;/STRONG&gt;Fix-up of changes to navigation properties and FKs is now performed automatically on DetectChanges and SaveChanges. It is also now possible to declare collections as ISet&amp;lt;T&amp;gt; in POCO objects. When either ICollection&amp;lt;T&amp;gt; or ISet&amp;lt;T&amp;gt; is used, the default collection type materialized is HashSet&amp;lt;T&amp;gt;, which among other advantages does not allow duplicate entries. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Lazy Loading on by Default in new Models: &lt;/STRONG&gt;When you create a new model in VS 2010, you get generated ObjectContext types that have lazy loading turned on by default (context.ContextOptions.LazyLoadingEnabled = true is placed in the constructor). This simplifies the default experience of working with objects. Of course, it is still possible to turn it off and do explicit and eager loading. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;EntityDataSource support for Query Extenders and POCO: &lt;/STRONG&gt;EntityDataSource now includes support for ASP.NET Query Extenders and POCO entities. Query Extenders are a new addition to ASP.NET that allow you to have more control over the data retrieval query of a Data Source, leveraging the LINQ capabilities of Entity Framework. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Support for Binary Keys: &lt;/STRONG&gt;The EF now allows you to have binary property types (and varbinary storage columns) mapped as Entity Key / Foreign Key. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ObjectMaterialized event: &lt;/STRONG&gt;It is now possible to write logic that is executed immediately after an object has been materialized. This event is raised after the scalar, complex and reference properties are populated (collections are filled afterwards). &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Object Services API improvements to enable N-Tier and Self Tracking Entities: &lt;/STRONG&gt;ObjectStateEntry.GetUpdatableOriginalValues method provides a access to an updatable data record that you can use to establish the original state of an entity at the property level. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Improvements to the generated SQL: &lt;/STRONG&gt;Numerous simplifications and improvements of the SQL generated when querying using the Entity Framework have been done including: removal of joins, better translation of certain functions,&amp;nbsp; elimination of constants used for internal purposes, which results in removing of levels of nesting and others. &lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Navigation Property Management&lt;/B&gt;: Users can now delete and add navigation properties, enabling the creation of one-way associations.&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Improved Database Generation&lt;/B&gt;: SQL CE support has been added. In addition, customization of database generation is significantly simpler now, with the ability to specify the DDL generation template to be used, as well as automatic discovery of installed database generation workflows and templates.&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;New Extensibility APIs&lt;/B&gt;: New APIs enable users to add custom properties to any object in the model and have those properties show up in the property sheet. In addition, other extension points allow for customization of models on load, save, and after the model creation and update wizards run.&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Generation of Complex Types from Stored Procedures&lt;/B&gt;: When creating a function import from a function, the UI can now detect the columns returned from a stored procedure and create a corresponding complex type. In addition, existing complex types can be updated when a stored procedure definition changes.&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Greatly Improved Facet Management&lt;/B&gt;: The designer can now distinguish between empty and blank values, and various property facet defaults are handled more cleanly and consistently.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;LINQ to Entities improvements:&lt;/STRONG&gt; Support for recognizing additional patterns in queries, simplification of EntityFunctions and SqlFunctions static classes and OrderBy is now lifted over filters and other operations.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;ADO.NET Data Services 4 Beta 2&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;Projections&lt;/B&gt;: This ADO.NET Data Services URI format has been extended to express projections (i.e. you can now work with a subset of the properties of an entity).&amp;nbsp; Beta 2 includes both server and client library (including LINQ support) support for projections.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Data Binding&lt;/B&gt;:&amp;nbsp; The data services client library for the .NET Framework 3.5 SP1 and Silverlight2 has been extended to support two-way data binding for WPF and Silverlight based applications.&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Row Count&lt;/STRONG&gt;: One scenario we heard a ton of feedback on after shipping V1 of ADO.NET Data Services in the .NET Framework 3.5SP1 is the ability for the a client of a data service to determine the total number of entities in a set without having to retrieve them all.&amp;nbsp; To address this need, we have extended the data services addressing scheme to allow a client to obtain this type of information without having to download all the entities in a set. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Feed Customization (aka "Web Friendly Feeds")&lt;/STRONG&gt;: A common ask we have received is to provide the ability to customize how entities are mapped into the various elements of an AtomPub feed.&amp;nbsp; This feature does just that by providing a data service author declarative control over how the data service runtime maps the properties of an entity (e.g. a Customer, Order, etc) to the elements of a feed. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Server Driven Paging (SDP)&lt;/STRONG&gt;: This one is best described by example.&amp;nbsp; If you had a data service that exposes photos, you likely want to limit the total number of photos a single request to the service can retrieve because the total collection of photos may be very large.&amp;nbsp; This feature allows a service author to set per collection limits on the total number of entities returned for each request.&amp;nbsp; In addition to limiting the number of photos returned per request, the server provides the client a "next link" which is simply a URI specifying how to continue retrieving the rest of the entities in the collection not returned by the first request.&amp;nbsp; For those familiar with AtomPub, this feature adds support for AtomPub &amp;lt;link rel="next" ...&amp;gt; elements to the data service runtime.&amp;nbsp;&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Enhanced BLOB Support&lt;/B&gt;: This feature enhances the BLOB support provided in V1 to enable data services to stream arbitrarily large BLOBs, store binary content separate from its metadata, easily defer the loading of BLOB content when its metadata is requested, etc.&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Request Pipeline&lt;/B&gt;: We have started to expose events throughout the data services server request processing pipeline.&amp;nbsp; For this release we’ll expose request level events and in future we’ll look to expose more fine grained events based on your feedback.&amp;nbsp; The goal of exposing our processing pipeline is to allow services further transparency into a data service such that a service author can do things such as setting HTTP response cache headers, wrapping interceptor processing and data service request processing in a single transaction, etc.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;New "Data Service Provider" Interface for Custom Provider Writers&lt;/STRONG&gt;: As the data services runtime has evolved, so has the number of ways people want to plug data into the data service framework.&amp;nbsp; In V1, two methods (Entity Framework and arbitrary .NET classes) were supported to enable a data service to interact with various diverse data sources.&amp;nbsp; To address another class of environments and data sources we have &lt;A href="http://blogs.msdn.com/pablo/archive/2008/11/01/ado-net-data-services-in-windows-azure-pushing-scalability-to-the-next-level.aspx" mce_href="http://blogs.msdn.com/pablo/archive/2008/11/01/ado-net-data-services-in-windows-azure-pushing-scalability-to-the-next-level.aspx"&gt;introduced a way to write a "custom" provider&lt;/A&gt; for those cases when the previous two provider models don't meet your needs. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Thank you, &lt;/P&gt;
&lt;P&gt;Elisa Flasko &lt;BR&gt;Program Manager, &lt;BR&gt;Data &amp;amp; Modeling Group&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9909581" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Visual+Studio+2010+Beta+2/default.aspx">Visual Studio 2010 Beta 2</category><category domain="http://blogs.msdn.com/adonet/archive/tags/What_2700_s+New/default.aspx">What's New</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category><category domain="http://blogs.msdn.com/adonet/archive/tags/What_2700_s+New+Data+Services/default.aspx">What's New Data Services</category></item><item><title>Improvements to the Generated SQL in .NET 4.0 Beta1</title><link>http://blogs.msdn.com/adonet/archive/2009/08/05/improvements-to-the-generated-sql-in-net-4-0-beta1.aspx</link><pubDate>Thu, 06 Aug 2009 07:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9858683</guid><dc:creator>dpblogs</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9858683.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9858683</wfw:commentRss><description>&lt;P&gt;One of the things that we are continuously working on improving is the quality and the readability of the SQL generated when querying using the Entity Framework. We have already made some improvements in .NET 4.0 Beta 1, and we are working on more for .NET 4.0 post Beta 1. &lt;/P&gt;
&lt;P&gt;Most of the improvements we have made are in the Entity Framework query pipeline as opposed to specific SqlClient changes. Because the changes were in the query pipeline, this results in simpler output command trees and thus would affect the SQL generated by any backend, not only by our SQL Server provider.&lt;/P&gt;
&lt;P&gt;Below we’ve highlighted the biggest improvements available in Beta 1 and then the ones that will be in the next public release of .NET Framework 4.0. Unless otherwise noted, the examples are based on the NorthwindEF Entity Data Model provided with the ADO.NET Entity Framework Query Samples (&lt;A href="http://code.msdn.microsoft.com/EFQuerySamples" mce_href="http://code.msdn.microsoft.com/EFQuerySamples"&gt;http://code.msdn.microsoft.com/EFQuerySamples&lt;/A&gt;). Also, in all the examples below, the parts of the SQL query highlighted in red have been removed and those in yellow have been added.&lt;/P&gt;
&lt;H4&gt;&lt;A title=_Toc225312799 name=_Toc225312799&gt;&lt;/A&gt;1. Avoid projecting all columns in nested queries&lt;/H4&gt;
&lt;P&gt;In some nested queries in the generated SQL, we used to explicitly project all columns that are brought in scope by the corresponding FROM clause, like the fragments marked red in the sample generated SQL below. Now, we instead only project the columns that are later referenced. This improvement is specific to our T-Sql Generation in SqlClient.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; query = (&lt;FONT color=#0000ff&gt;from&lt;/FONT&gt; p &lt;SPAN class=kwrd&gt;&lt;FONT color=#0000ff&gt;in&lt;/FONT&gt;&lt;/SPAN&gt; context.Products&lt;BR&gt;                 &lt;FONT color=#0000ff&gt;orderby&lt;/FONT&gt; p.ProductName&lt;BR&gt;                 &lt;FONT color=#0000ff&gt;select&lt;/FONT&gt; p.ProductName)&lt;BR&gt;                 .Skip(2).Take(2);&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_2.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; WIDTH: 500px; DISPLAY: inline; HEIGHT: 340px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb.png" width=459 height=321 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H4&gt;2. Avoiding Unnecessary IS NULL Checks in LINQ to Entities Queries&lt;/H4&gt;
&lt;P&gt;When translating joins in LINQ to Entities, we check whether the columns on which the join is specified are equal or both are null. In the cases when one (or both) of the columns is non-nullable, the “IS NULL” check is redundant and has been removed. This improvement is in the Entity Framework query pipeline. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; query = context.Products.Join(&lt;BR&gt;context.Categories, &lt;BR&gt;p =&amp;gt; p.ProductID,&lt;BR&gt;c =&amp;gt; c.CategoryID,&lt;BR&gt;(p, c) =&amp;gt; &lt;FONT color=#0000ff&gt;&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; &lt;/FONT&gt;{ p.ProductID, c.CategoryID, p.ProductName, c.CategoryName });&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_4.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_4.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_1.png" width=532 height=310 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H4&gt;3&lt;A title=_Toc225312807 name=_Toc225312807&gt;&lt;/A&gt;. Additional join elimination:&amp;nbsp; Eliminate parent table in “Child Left Outer Join Parent”&lt;/H4&gt;
&lt;P&gt;In scenarios where a given table is explicitly or implicitly (e.g. via a navigation property) joined to a parent table (i.e. table to which it has a foreign key constraint) we were not eliminating the parent table even if the only columns referenced from that table were the columns comprising the primary key and could have been reused from the child table. (Note: The parent-child terminology assumes that there is foreign key relationship between these tables specified in the SSDL). This improvement is in the Entity Framework query pipeline.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Note: For this example the highlighted following fragments need to be added to the SSDL in the ADO.NET Entity Framework Query Samples noted above:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_6.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_6.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_2.png" width=464 height=330 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_2.png"&gt;&lt;/A&gt; &lt;/EM&gt;&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt;&lt;/SPAN&gt; entitySQL = &lt;SPAN class=str&gt;&lt;FONT color=#800000&gt;"SELECT p.Category.CategoryId FROM Products as p"&lt;/FONT&gt;&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;DIV class=csharpcode-wrapper&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_8.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_8.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_3.png" width=472 height=178 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_3.png"&gt;&lt;/A&gt; &lt;/DIV&gt;
&lt;P&gt;For LINQ to Entities in .NET Framework 3.5 SP1 the equivalent query resulted in the same generated query for Entity SQL shown in the After sample.&lt;/P&gt;
&lt;H4&gt;4. Using IN instead of nested OR’s &lt;/H4&gt;
&lt;P&gt;Comparing a column to multiple values, either as a result of the explicit use of Entity SQL’s IN expression or as result of internally generated checks over a type discriminator value used to result in nested OR expressions in the generated SQL. Now, we are instead producing an IN expression. This improvement is specific to our T-Sql Generation in SqlClient.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt;&lt;/SPAN&gt; entitySQL = &lt;SPAN class=str&gt;&lt;FONT color=#800000&gt;"SELECT p FROM Products as p where p.ProductId in {1, 2, 3, 4, 5}"&lt;/FONT&gt;&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_10.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_10.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_4.png" width=462 height=472 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_4.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/DIV&gt;
&lt;DIV class=csharpcode-wrapper&gt;&lt;BR&gt;Starting with.NET 4.0 Beta 1 Entity Framework, a LINQ version of this query is also supported:&lt;/DIV&gt;
&lt;DIV class=csharpcode-wrapper&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; query = context.Products.Where(p =&amp;gt; &lt;FONT color=#0000ff&gt;&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt;&lt;/FONT&gt;[] { 1, 2, 3, 4, 5 }.Contains(p.ProductID));    &lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;The resulting generated TSQL also takes advantage of this improvement:&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_12.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_12.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_5.png" width=461 height=185 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_5.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/DIV&gt;
&lt;H4&gt;5. Translating more of LINQ’s GroupBy operator into GROUP BY&lt;/H4&gt;
&lt;P&gt;LINQ’s GroupBy operator is richer then SQL’s group by clause. For example, in addition to aggregates over a group it can return the entire group. When translating LINQ’s GroupBy, we try to recognize if it can be expressed by SQL’s group by (i.e. DbGroupByExpression without a group partition), otherwise we translate it into a more complex expression involving a join to the input table. &lt;/P&gt;
&lt;P&gt;In Entity Framework 4.0 Beta1 we have expanded the cases that we are able to translate into SQL’s GroupBy. This improvement is in the Entity Framework query pipeline.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; query = context.Products.Where(p =&amp;gt; p.ProductID &amp;lt; 4)&lt;BR&gt;            .GroupBy(p =&amp;gt; p.ProductID, p =&amp;gt; p.ProductID, (key, group) =&amp;gt; &lt;BR&gt;            &lt;SPAN class=kwrd&gt;&lt;FONT color=#0000ff&gt;new&lt;/FONT&gt;&lt;/SPAN&gt; { Key = key, Max = group.Max() });&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_14.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_14.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_6.png" width=478 height=383 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_6.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H4&gt;6. Avoiding “Cast (1 as bit)”, using “1” instead&lt;/H4&gt;
&lt;H4&gt;&lt;/H4&gt;
&lt;P&gt;In cases when we need an internally generated constant, like when translating EntitySQL Exists expression or IEnumerable.Count in LINQ to Entities, we previously used “true”, which translates to “cast(1 as bit)” on SQL Server. We now instead use the integer constant 1, which translates to “1”. This improvement is in the Entity Framework query pipeline.&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; query = context.Categories.Select(c =&amp;gt; &lt;SPAN class=kwrd&gt;&lt;FONT color=#0000ff&gt;new&lt;/FONT&gt;&lt;/SPAN&gt; { c.CategoryID, count = c.Products.Count() });&lt;/PRE&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_16.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_16.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_7.png" width=477 height=335 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_7.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/DIV&gt;
&lt;H4&gt;7. Simplifying some queries that go against a subtype in a type hierarchy&lt;/H4&gt;
&lt;P&gt;In some cases when a query is only interested in entities of a particular subtype (specified via OfType or IsOf for example) we used to query using a view over the base type and thus possibly generate some unnecessary case statements to also check for the types that are not of the desired subtype. This improvement allows us to use the simplified query view that is only over the desired subtype and thereby generate a simpler provider query. &lt;/P&gt;
&lt;P&gt;The following example that illustrates that is over a schema with a TPH mapping with the inheritance hierarchy as shown in the figure. This improvement is in the Entity Framework query pipeline.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/image_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/image_thumb.png" width=417 height=523 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;DIV id=codeSnippetWrapper class=csharpcode-wrapper&gt;&lt;PRE id=codeSnippet class=csharpcode&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; query = &lt;SPAN class=kwrd&gt;&lt;FONT color=#0000ff&gt;this&lt;/FONT&gt;&lt;/SPAN&gt;.tph.Entities.OfType&amp;lt;Tph.&lt;FONT color=#4e9a9a&gt;Derived1&lt;/FONT&gt;&amp;gt;().GroupBy(d2 =&amp;gt; d2).Select(p =&amp;gt; p.Max(g =&amp;gt; g.Id));&lt;/PRE&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_18.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_18.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_8.png" width=415 height=437 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_8.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_20.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_20.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=blog1 border=0 alt=blog1 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_9.png" width=416 height=196 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/acb92c99bd6c_EE69/blog1_thumb_9.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H3&gt;Improvements in .NET 4.0 post Beta1&lt;/H3&gt;
&lt;P&gt;Here is a quick overview of the improvements that we are working on for this release but are not included in Beta1:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Elimination of null sentinels – In the output query there is often the constant 1 projected both in nested and in top-most queries. By avoiding it and reusing other columns for the same purpose in many cases we are able to avoid levels of nesting. &lt;/LI&gt;
&lt;LI&gt;Additional Join Elimination &lt;/LI&gt;
&lt;LI&gt;Use of Inner Joins instead of Left Outer Joins when possible&lt;/LI&gt;
&lt;LI&gt;Provide mechanism for efficient queries on non-Unicode columns – We now generate non-unicode constants and parameters when these are used in LINQ to Entities queries in comparisons with non-unicode columns. This allows indexes to be used by SQL Server.&lt;/LI&gt;
&lt;LI&gt;Improve the translation of the functions String.StartsWith, String.Contains and String.EndsWith in LINQ to Entites to use LIKE. &lt;/LI&gt;
&lt;LI&gt;Improve the translation of the canonical functions StartsWith, Contains and EndsWith to use LIKE (these canonical functions became available in .NET 4.0 Beta1)&lt;/LI&gt;
&lt;LI&gt;Collapse multiple Case statements into one&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;Kati Iceva&lt;BR&gt;Software Development Engineer, Entity Framework&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9858683" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>Customizing T4 Templates</title><link>http://blogs.msdn.com/adonet/archive/2009/07/22/customizing-t4-templates.aspx</link><pubDate>Wed, 22 Jul 2009 18:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9845103</guid><dc:creator>dpblogs</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9845103.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9845103</wfw:commentRss><description>&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The whole point of us using T4 for code-generation is that it makes it easy to customize the generated entities.&lt;/p&gt;
&lt;p&gt;A good example might be to support some sort of validation when setting string properties.&lt;/p&gt;
&lt;p&gt;To illustrate lets re-use the &lt;a href="http://blogs.msdn.com/adonet/attachment/9798363.ashx" mce_href="http://blogs.msdn.com/adonet/attachment/9798363.ashx"&gt;code&lt;/a&gt; from the recent &lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-poco-templates-for-entity-framework.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-poco-templates-for-entity-framework.aspx"&gt;POCO template walkthrough post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In that project there is a Person entity which has an EmailAddress property. If we want this property to only accept valid EmailAddresses, we need to modify the generated code to do some validation, probably using a Regular Expression.&lt;/p&gt;
&lt;p&gt;One way to do this is to use Structural Annotations in conjunction with a customized T4 template. &lt;a href="http://blogs.msdn.com/efdesign/archive/2008/08/12/structural-annotations-one-pager.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/08/12/structural-annotations-one-pager.aspx"&gt;Structural Annotations&lt;/a&gt;, if you aren’t familiar with them, allow you to put custom annotations in the model and retrieve them using the Entity Frameworks metadata APIs. So we can use Structural Annotations to embed our Regular Expressions right in the model, and access them from inside the T4 template, which already uses the Entity Framework’s metadata APIs.&lt;/p&gt;
&lt;p&gt;To do this, the first step is to register a custom namespace in the schema element of the CSDL portion of the EDMX file:&lt;/p&gt;
&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;edmx:ConceptualModels&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Schema&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://schemas.microsoft.com/ado/2008/09/edm"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:store&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"&lt;/span&gt; &lt;br&gt;              &lt;span style="color: rgb(255, 0, 0);"&gt;xmlns:Regex&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://Regex"&lt;/span&gt;&lt;br&gt;              &lt;span style="color: rgb(255, 0, 0);"&gt;Namespace&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogging"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Alias&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Self"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EntityContainer&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="BloggingContainer"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EntitySet&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogs"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;EntityType&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogging.Blog"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EntitySet&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="People"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;EntityType&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogging.Person"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EntitySet&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Entrys"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;EntityType&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogging.Entry"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;/div&gt;
&lt;p&gt;With that in place we can put the Regular Expression on our EmailAddress property by putting some custom XML, in the namespace we just registered, inside the corresponding Property. &lt;/p&gt;
&lt;p&gt;Something like this:&lt;/p&gt;
&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EntityType&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Person"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Key&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;PropertyRef&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ID"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Key&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Property&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Int32"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="ID"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Nullable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="false"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;store:StoreGeneratedPattern&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Identity"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Property&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="String"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Firstname"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Nullable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="false"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;MaxLength&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="50"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Property&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="String"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Surname"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Nullable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="false"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;MaxLength&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="50"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Property&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="String"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="EmailAddress"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Nullable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="false"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;MaxLength&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="100"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Regex:Expression&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="A valid emailaddress is required"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Regex:Expression&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Property&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;NavigationProperty&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Entries"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Relationship&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogging.PostPerson"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;FromRole&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Person"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;ToRole&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Post"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;NavigationProperty&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogs"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Relationship&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blogging.PersonBlog"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;FromRole&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Person"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;ToRole&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Blog"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EntityType&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;/div&gt;
&lt;p&gt;I’m using this regular expression: “&lt;i&gt;^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]&lt;/i&gt;&lt;i&gt;+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$&lt;/i&gt;” but the of course any Regular expression would work. &lt;/p&gt;
&lt;p&gt;The ErrorMessage attribute is there so it can be used as the Message of an Exception in the event of a non-match.&lt;/p&gt;
&lt;p&gt;Once you have this Regular Expression in your model, you can modify your T4 template (in this case the template is the POCO Types template that ships with the &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9"&gt;Microsoft Entity Framework Feature CTP 1&lt;/a&gt;), so that it looks for and handles Regular Expressions.&lt;/p&gt;
&lt;p&gt;So rather than this:&lt;/p&gt;
&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; EmailAddress { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; &lt;font color="#0000ff"&gt;set&lt;/font&gt;; }&lt;/pre&gt;&lt;br&gt;&lt;/div&gt;
&lt;p&gt;We want to produce something like this:&lt;/p&gt;
&lt;div style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; cursor: text;" id="codeSnippetWrapper"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt;" id="codeSnippet"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; _EmailAddress; &lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;font color="#55aaaa"&gt;Regex&lt;/font&gt; _EmailAddressRegex = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;font color="#55aaaa"&gt;Regex&lt;/font&gt;(&lt;span style="color: rgb(0, 96, 128);"&gt;&lt;font color="#800000"&gt;@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$"&lt;/font&gt;&lt;/span&gt;);&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; EmailAddress &lt;br&gt;        { &lt;br&gt;             &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _EmailAddress; }&lt;br&gt;             &lt;font color="#0000ff"&gt;set&lt;/font&gt; &lt;br&gt;             { &lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt; != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; !_EmailAddressRegex.IsMatch(&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;))&lt;br&gt;                   &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Exception(&lt;span style="color: rgb(0, 96, 128);"&gt;&lt;font color="#800000"&gt;"A valid emailaddress is required"&lt;/font&gt;&lt;/span&gt;);&lt;br&gt;                _EmailAddress = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;; &lt;br&gt;             }&lt;br&gt;        }&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;/div&gt;
&lt;p&gt;To make this change to the generated code there are three parts of the template that need to change:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A change to the part of the template that emits primitive properties: &lt;br&gt;&lt;/li&gt;&amp;lt;#=Accessibility.ForType(entity)#&amp;gt; &amp;lt;#=code.SpaceAfter(code.AbstractOption(entity))#&amp;gt;partial class &amp;lt;#=code.Escape(entity)#&amp;gt;&amp;lt;#=code.StringBefore(" : ", code.Escape(entity.BaseType))#&amp;gt; &lt;br&gt;{ &lt;br&gt;&amp;lt;# &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; region.Begin("Primitive Properties"); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (EdmProperty edmProperty in entity.Properties.Where(p =&amp;gt; p.TypeUsage.EdmType is PrimitiveType &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;&amp;amp; p.DeclaringType == entity)) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { #&amp;gt;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;lt;# if (HasRegex(edmProperty)) { #&amp;gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private &amp;lt;#=code.Escape(edmProperty.TypeUsage)#&amp;gt; _&amp;lt;#=code.Escape(edmProperty)#&amp;gt;; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private Regex _&amp;lt;#=code.Escape(edmProperty)#&amp;gt;Regex = new Regex(@"&amp;lt;#= GetRegexElement(edmProperty).Value #&amp;gt;"); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;#=Accessibility.ForProperty(edmProperty)#&amp;gt; &amp;lt;#=code.Escape(edmProperty.TypeUsage)#&amp;gt; &amp;lt;#=code.Escape(edmProperty)#&amp;gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;#=code.SpaceAfter(Accessibility.ForGetter(edmProperty))#&amp;gt;get { return _&amp;lt;#=code.Escape(edmProperty)#&amp;gt;; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;#=code.SpaceAfter(Accessibility.ForSetter(edmProperty))#&amp;gt;set &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (value != null &amp;amp;&amp;amp; !_&amp;lt;#=code.Escape(edmProperty)#&amp;gt;Regex.IsMatch(value)) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new Exception("&amp;lt;#=GetRegexErrorMessage(edmProperty)#&amp;gt;"); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _&amp;lt;#=code.Escape(edmProperty)#&amp;gt; = value; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;lt;# } else { #&amp;gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;#=Accessibility.ForProperty(edmProperty)#&amp;gt; &amp;lt;#=code.Escape(edmProperty.TypeUsage)#&amp;gt; &amp;lt;#=code.Escape(edmProperty)#&amp;gt; { &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;#=code.SpaceAfter(Accessibility.ForGetter(edmProperty))#&amp;gt;get; &amp;lt;#=code.SpaceAfter(Accessibility.ForSetter(edmProperty))#&amp;gt;set; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;lt;# } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; region.End(); &lt;br&gt;#&amp;gt; &lt;br&gt;&lt;br&gt;
&lt;li&gt;Some utility functions (used above), that use the Entity Framework Metadata APIs to access the Regular Expression: &lt;br&gt;&lt;br&gt;&lt;/li&gt;
&lt;p&gt;MetadataProperty GetRegexProperty(EdmProperty property)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;return property.MetadataProperties.FirstOrDefault(mp =&amp;gt; mp.Name == "http://Regex:Expression");&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;bool HasRegex(EdmProperty property)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;return GetRegexProperty(property) != null;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;System.Xml.Linq.XElement GetRegexElement(EdmProperty property)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;var prop = GetRegexProperty(property);&lt;/p&gt;
&lt;p&gt;if (prop == null) throw new Exception("No Regex found");&lt;/p&gt;
&lt;p&gt;var node = prop.Value as System.Xml.Linq.XElement;&lt;/p&gt;
&lt;p&gt;if (node == null) throw new Exception("No Regex found");&lt;/p&gt;
&lt;p&gt;return node;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;string GetRegexErrorMessage(EdmProperty property)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;var node = GetRegexElement(property); &lt;/p&gt;
&lt;p&gt;var messageAttr = node.Attribute("ErrorMessage");&lt;/p&gt;
&lt;p&gt;if (messageAttr == null) &lt;/p&gt;
&lt;p&gt;return "Regular Expression check for " + property.Name + " failed.";&lt;/p&gt;
&lt;p&gt;else &lt;/p&gt;
&lt;p&gt;return messageAttr.Value;&lt;/p&gt;
&lt;p&gt;} &lt;br&gt;&lt;/p&gt;
&lt;li&gt;And something to make the generated classes use System.Text.RegularExpressions: &lt;br&gt;&lt;br&gt;&lt;/li&gt;
&lt;p&gt;&amp;lt;#&lt;/p&gt;
&lt;p&gt;void WriteHeader(string namespaceName, CodeGenerationTools code, params string[] extraUsings)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;CodeRegion region = new CodeRegion(this);&lt;/p&gt;
&lt;p&gt;#&amp;gt;&lt;/p&gt;
&lt;p&gt;//------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;// &amp;lt;auto-generated&amp;gt;&lt;/p&gt;
&lt;p&gt;// This code was generated from a template.&lt;/p&gt;
&lt;p&gt;//&lt;/p&gt;
&lt;p&gt;// Changes to this file may cause incorrect behavior and will be lost if&lt;/p&gt;
&lt;p&gt;// the code is regenerated.&lt;/p&gt;
&lt;p&gt;// &amp;lt;/auto-generated&amp;gt;&lt;/p&gt;
&lt;p&gt;//------------------------------------------------------------------------------&lt;/p&gt;
&lt;p&gt;using System;&lt;/p&gt;
&lt;p&gt;using System.Collections.Generic;&lt;/p&gt;
&lt;p&gt;using System.Text.RegularExpressions;&lt;/p&gt;&lt;/ol&gt;
&lt;p&gt;Now if you replace your POCO Types T4 template with the template attached below, the generated classes will enforce any regular expressions you add to your model. To find the changes in the T4 template just find ‘Regex’ and ‘RegularExpression’.&lt;/p&gt;
&lt;p&gt;This is just scratching the surface though, you could really run with this idea, perhaps producing &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx"&gt;DataAnnotations&lt;/a&gt; directly from the EDM so that they can be used by frameworks like &lt;a href="http://www.asp.net/dynamicdata/" mce_href="http://www.asp.net/dynamicdata/"&gt;Dynamic Data&lt;/a&gt;? &lt;/p&gt;
&lt;p&gt;Your options are almost unlimited.&lt;/p&gt;
&lt;p&gt;Have fun! &lt;br&gt;&lt;a href="http://blogs.msdn.com/alexj" mce_href="http://blogs.msdn.com/alexj"&gt;Alex James &lt;/a&gt;&lt;br&gt;Entity Framework Team&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9845103" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adonet/attachment/9845103.ashx" length="15527" type="application/octet-stream" /><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/POCO/default.aspx">POCO</category></item><item><title>Entity Framework Provider for Synergy DBMS</title><link>http://blogs.msdn.com/adonet/archive/2009/07/01/entity-framework-provider-for-synergy-dbms.aspx</link><pubDate>Wed, 01 Jul 2009 20:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9811918</guid><dc:creator>dpblogs</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9811918.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9811918</wfw:commentRss><description>&lt;DIV class=postcontent&gt;&lt;FONT size=3 face=Calibri&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;It is my pleasure to announce that Synergex has released their Synergy/DE Data Provider for .NET with support for the Entity Framework. The Synergy/DE Data Provider for .NET enables developers to access Synergy DBMS databases from .NET applications and Visual Studio 2008 and to take advantage of the Entity Framework and LINQ. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;For more information, see the Synergex announcement page about the release &lt;A href="http://www.synergyde.com/news/article.aspx?id=3197" mce_href="http://www.synergyde.com/news/article.aspx?id=3197"&gt;here&lt;/A&gt;.&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;Congratulations to everyone at&amp;nbsp;Synergex who contributed to the release!&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;Enjoy!&lt;/SPAN&gt;&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;&lt;/SPAN&gt;Elisa Flasko&lt;BR&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 13.5pt"&gt;Program Manager, Data Programmability&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9811918" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Providers/default.aspx">Providers</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Synergex/default.aspx">Synergex</category></item><item><title>Feature CTP Walkthrough: Code Only for Entity Framework</title><link>http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-entity-framework.aspx</link><pubDate>Tue, 23 Jun 2009 00:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9798382</guid><dc:creator>dpblogs</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9798382.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9798382</wfw:commentRss><description>&lt;FONT size=3 face=Calibri&gt;
&lt;H3&gt;Overview&lt;/H3&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;This post covers a new Entity Framework extension called Code Only. Code Only allows you to use the Entity Framework using POCO entities and without an EDMX file, i.e. with ‘Code Only’. This walkthrough shows you how to use the first release of Code Only, which is a very early and limited preview of our long term plans for Code Only. To get an idea of where Code Only is heading look at &lt;A href="http://blogs.msdn.com/efdesign/archive/2009/06/10/code-only.aspx"&gt;&lt;FONT color=#0000ff&gt;this post&lt;/FONT&gt;&lt;/A&gt; on the &lt;A href="http://blogs.msdn.com/efdesign"&gt;EF Design Blog&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;Code Only ships as part of the Microsoft Entity Framework Feature CTP 1. The CTP works on top of the latest version of the Entity Framework released as part of .NET 4.0 Beta1, and you can download it &lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9"&gt;here&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;SPAN style="BACKGROUND: yellow; mso-highlight: yellow"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;STRONG&gt;Requirements&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;This walkthrough requires Visual Studio 2010 Beta 1 &lt;/LI&gt;
&lt;LI&gt;The Microsoft Entity Framework Feature CTP1, that can be downloaded from &lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9"&gt;here&lt;/A&gt;. &lt;/LI&gt;
&lt;LI&gt;A local SQL Server 2008 Express instance has to be installed as SQLEXPRESS. Otherwise, changes to the connection string in the web.config file or regenerating the database from the included SQL scripts may be necessary. &lt;/LI&gt;
&lt;LI&gt;Download and extract the initial solution attached to this post. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx" mce_href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx"&gt;Read More…&lt;/A&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9798382" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adonet/attachment/9798382.ashx" length="7680" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Feature+CTP1+for+.NET+4.0/default.aspx">Entity Framework Feature CTP1 for .NET 4.0</category></item><item><title>Feature CTP Walkthrough: POCO Templates for Entity Framework</title><link>http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-poco-templates-for-entity-framework.aspx</link><pubDate>Tue, 23 Jun 2009 00:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9798363</guid><dc:creator>dpblogs</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9798363.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9798363</wfw:commentRss><description>&lt;H3&gt;Overview&lt;/H3&gt;
&lt;P&gt;This post covers a new Entity Framework extension called POCO Templates. POCO Templates is a T4 template and associated include files, that allow you to generate POCO classes or Plain Old CLR Objects for use with the Entity Framework. T4 templates are used because T4 makes it easy to customize your Entities. &lt;/P&gt;
&lt;P&gt;POCO Templates ship as part of the Microsoft Entity Framework Feature CTP 1. The CTP works on top of the latest version of the Entity Framework released as part of .NET 4.0 Beta1, and you can download it &lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9"&gt;&lt;FONT color=#4271d6&gt;here&lt;/FONT&gt;&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Requirements&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;This walkthrough requires Visual Studio 2010 Beta 1 &lt;/LI&gt;
&lt;LI&gt;The Microsoft Entity Framework Feature CTP1, that can be downloaded from &lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9"&gt;here&lt;/A&gt;. &lt;/LI&gt;
&lt;LI&gt;A local SQL Server 2008 Express instance has to be installed as SQLEXPRESS. Otherwise, changes to the connection string in the web.config file or regenerating the database from the included SQL scripts may be necessary. &lt;/LI&gt;
&lt;LI&gt;Download and extract the initial solution attached to this post. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-framework.aspx" mce_href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-framework.aspx"&gt;Read More…&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9798363" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adonet/attachment/9798363.ashx" length="31414" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Feature+CTP1+for+.NET+4.0/default.aspx">Entity Framework Feature CTP1 for .NET 4.0</category></item><item><title>Feature CTP Walkthrough: Self Tracking Entities for Entity Framework</title><link>http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-self-tracking-entities-for-entity-framework.aspx</link><pubDate>Mon, 22 Jun 2009 23:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9798233</guid><dc:creator>dpblogs</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9798233.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9798233</wfw:commentRss><description>&lt;H3&gt;Overview&lt;/H3&gt;
&lt;P&gt;The goal of the following walkthrough is to demonstrate a basic scenario for the use of Self Tracking Entities with Entity Framework. Self Tracking Entities is a feature included in the Microsoft Entity Framework Community Technology Preview 1, which consists of a new API added to the ObjectContext and ObjectSet classes (implemented as extension methods for the Feature CTP) and a code-generation template based on Text Template Transformation Toolkit (T4) technology included in Visual Studio. &lt;/P&gt;
&lt;P&gt;Self Tracking Entities are domain classes that do not have any dependency on Entity Framework but include mechanisms that allow them to track changes on scalar and complex property values, references and collections within themselves, independently of the Entity Framework.&lt;/P&gt;
&lt;P&gt;The first scenario we are trying to address with Self Tracking Entities is one in which a WCF service exposes a series of operations that return entity graphs, then a client application can manipulate that graph and submit the modifications to a service operation that validates and performs the updates to a database store using Entity Framework.&lt;/P&gt;
&lt;H3&gt;Requirements&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;This walkthrough requires Visual Studio 2010 Beta 1&lt;/LI&gt;
&lt;LI&gt;The Microsoft Entity Framework Feature CTP1, that can be downloaded from &lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9" mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=7fd7164e-9e73-43f7-90ab-5b2bf2577ac9"&gt;here&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;A local SQL Server 2008 Express instance has to be installed as SQLEXPRESS. Otherwise, changes to the connection string in the web.config file or regenerating the database from the included SQL scripts may be necessary.&lt;/LI&gt;
&lt;LI&gt;Download and extract the initial solution attached to this post.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-self-tracking-entities-for-the-entity-framework.aspx" mce_href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-self-tracking-entities-for-the-entity-framework.aspx"&gt;Read More...&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9798233" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adonet/attachment/9798233.ashx" length="392824" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework+Feature+CTP1+for+.NET+4.0/default.aspx">Entity Framework Feature CTP1 for .NET 4.0</category></item><item><title>POCO in the Entity Framework : Part 2 – Complex Types, Deferred Loading and Explicit Loading</title><link>http://blogs.msdn.com/adonet/archive/2009/05/28/poco-in-the-entity-framework-part-2-complex-types-deferred-loading-and-explicit-loading.aspx</link><pubDate>Thu, 28 May 2009 19:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9647609</guid><dc:creator>dpblogs</dc:creator><slash:comments>42</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9647609.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9647609</wfw:commentRss><description>&lt;P&gt;In my post last week on the &lt;A href="http://blogs.msdn.com/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx"&gt;POCO Experience in Entity Framework&lt;/A&gt;, I covered the fundamentals of POCO support in Entity Framework 4.0. In this post, I’ll cover a few more aspects related to POCO.&lt;/P&gt;
&lt;H4&gt;Complex Types&lt;/H4&gt;
&lt;P&gt;Complex Types are supported in POCO just like they are with regular &lt;B&gt;EntityObject&lt;/B&gt; based entities. All you have to do is declare your complex types as POCO classes and then use them for declaring the complex type based properties on your POCO entities.&lt;/P&gt;
&lt;P&gt;As an example, here’s an &lt;B&gt;InventoryDetail&lt;/B&gt; complex type to represent a part of my Product entity:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;FONT color=#55aaaa&gt;InventoryDetail&lt;BR&gt;&lt;/FONT&gt;{&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;FONT color=#58abab&gt;Int16&lt;/FONT&gt; UnitsInStock { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;FONT color=#55aaaa&gt;Int16&lt;/FONT&gt; UnitsOnOrder { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;FONT color=#53a6a6&gt;Int16&lt;/FONT&gt; ReorderLevel { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;} &lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;My &lt;B&gt;Product&lt;/B&gt; class now has been modified to include a property of this type to group the inventory detail fields:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;FONT color=#50a0a0&gt;Product&lt;BR&gt;&lt;/FONT&gt;{&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; ProductID { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ProductName { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; SupplierID { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; QuantityPerUnit { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;decimal&lt;/SPAN&gt; UnitPrice { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;FONT color=#53a6a6&gt;InventoryDetail&lt;/FONT&gt; InventoryDetail { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; Discontinued { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;FONT color=#55aaaa&gt;Category&lt;/FONT&gt; Category { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;}&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;You can then do everything you are used to doing with Complex Types. Here’s how I use it in a query:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; outOfStockProducts = &lt;FONT color=#0000ff&gt;from&lt;/FONT&gt; c &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; context.Products&lt;BR&gt;                         &lt;SPAN style="COLOR: #0000ff"&gt;where&lt;/SPAN&gt; c.InventoryDetail.UnitsInStock == 0&lt;BR&gt;                         &lt;FONT color=#0000ff&gt;select&lt;/FONT&gt; c;&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, Complex Type support with POCO is really straightforward to use. There are a couple of things you need to keep in mind when using complex types support with POCO:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You must define your Complex Type as a class. Structs are not supported.&lt;/LI&gt;
&lt;LI&gt;You cannot use inheritance with your complex type classes.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;While we are on the topic of Complex Types, I thought I’d mention one other thing: Did you know that the Entity Framework designer in Visual Studio 2010 supports complex type declarations? &lt;/P&gt;
&lt;P&gt;In Visual Studio 2008, you had to manually add the Complex Type declaration to the CSDL. That is all history with the Complex Type support in the designer in Visual Studio 2010.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_thumb.png" width=491 height=361 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;And what’s cool is that because Visual Studio 2010 supports Multi-Targeting, you can use this capability when building applications that target .NET Framework 3.5, using Entity Framework 3.5 as well!&lt;/P&gt;
&lt;H4&gt;Deferred/Lazy Loading&lt;/H4&gt;
&lt;P&gt;In my &lt;A href="http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-deferred-loading-in-entity-framework-4-0.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-deferred-loading-in-entity-framework-4-0.aspx"&gt;sneak preview post on Deferred Loading&lt;/A&gt; two weeks ago, I mentioned that there is now Deferred Loading support in Entity Framework. It comes as no surprise then that the default code-generated entity types out of the box based on &lt;B&gt;EntityObject&lt;/B&gt; will offer Deferred Loading. If you are wondering whether Deferred Loading is supported with POCO objects, then I think you will be happy to know that you can get Deferred Loading with POCO as well.&lt;/P&gt;
&lt;P&gt;There are two things you need to do in order to get Deferred Loading support with POCO entities:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Declare the property that you would like to load lazily as &lt;B&gt;virtual. &lt;/B&gt;These properties can be any collection type that implements &lt;B&gt;ICollection&amp;lt;T&amp;gt; &lt;/B&gt;or they can be a reference representing a 1/0..1 relationship.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;For instance, here’s a part of the updated &lt;B&gt;Category&lt;/B&gt; entity class which I have modified to support Deferred Loading:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;FONT color=#4b9696&gt;Category&lt;/FONT&gt;&lt;BR&gt;{&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; CategoryID { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; CategoryName { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; Description { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;byte&lt;/SPAN&gt;[] Picture { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;FONT color=#4e9c9c&gt;List&lt;/FONT&gt;&amp;lt;&lt;FONT color=#4a9595&gt;Product&lt;/FONT&gt;&amp;gt; Products { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    ...&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2.&amp;nbsp;&amp;nbsp; Enable deferred loading on the context: &lt;BR&gt;&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;context.ContextOptions.DeferredLoadingEnabled = &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That’s it. You will now get automatic Deferred Loading for your POCO types without having to do anything else.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;So how exactly does this work and what’s going on under the covers? &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The reason why this works is because when I marked my collection property as &lt;B&gt;virtual&lt;/B&gt;, this allowed the Entity Framework to provide a &lt;B&gt;proxy&lt;/B&gt; instance for my POCO type at runtime, and it is this proxy that does automatic deferred loading. The proxy instance is based on a type that derives from my own POCO entity class - so all functionality you have provided is preserved. From a developer point of view, this allows you to write persistence ignorant code even when deferred loading might be a requirement.&lt;/P&gt;
&lt;P&gt;If you were to inspect the actual instance in the debugger, you will see that the underlying type for the instance is different from the original type that I declared:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_4.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_thumb_1.png" width=492 height=179 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart2ComplexType_148A3/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;While the Entity Framework does its best to provide automatic deferred loading with minimal friction, this is something you need to be aware of when dealing with manual creation of instances that you want to then add or attach, or when you serialize/deserialize instances.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Manual instantiation of Proxy instances for POCO entities&lt;/U&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;In order to enable creation of proxy instances for adding/attaching, you can use the CreateObject factory method on ObjectContext for creating entity instances:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;FONT color=#0000ff&gt;Category&lt;/FONT&gt; category = context.CreateObject&amp;lt;&lt;FONT color=#53a6a6&gt;Category&lt;/FONT&gt;&amp;gt;();&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try to keep this in mind and use &lt;B&gt;CreateObject&lt;/B&gt; when creating instances that you want to then use with the Entity Framework.&lt;/P&gt;
&lt;H4&gt;More Efficient Change Tracking with “Change Tracking Proxies”&lt;/H4&gt;
&lt;P&gt;The standard POCO entities we have talked about until now rely on snapshot based change tracking – i.e. the Entity Framework will maintain snapshots of before values and relationships of the entities so that they can be compared with current values later during Save. However, this comparison is relatively expensive when compared to the way change tracking works with EntityObject based entities. &lt;/P&gt;
&lt;P&gt;There is another type of proxy that will allow you to get better performance out of change tracking with POCO entities.&lt;/P&gt;
&lt;P&gt;If you are familiar with IPOCO, you know that &lt;B&gt;IEntityWithChangeTracker &lt;/B&gt;was one of the interfaces you were required to implement to provide change notifications to the Entity Framework.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Change Tracking proxies &lt;/B&gt;subclass your POCO entity class to provide you with this capability during runtime without requiring you to implement the IPOCO interfaces yourself. &lt;/P&gt;
&lt;P&gt;In many ways, you get the best of both worlds with this approach: You get persistence ignorance with POCO classes and you get the performance of &lt;B&gt;EntityObject&lt;/B&gt; / &lt;B&gt;IPOCO&lt;/B&gt; when it comes to change tracking. &lt;/P&gt;
&lt;P&gt;To get change tracking proxies, the basic rule is that your class must be public, non-abstract or non-sealed. Your class must also implement public virtual getters/setters for all properties that are persisted. Finally, you must declare collection based relationship navigation properties as ICollection&amp;lt;T&amp;gt; only. They cannot be a concrete implementation or another interface that derives from ICollection&amp;lt;T&amp;gt; (a difference from the Deferred Loading proxy)&lt;/P&gt;
&lt;P&gt;Here’s an example of my POCO class for &lt;B&gt;Product&lt;/B&gt; that will give me more efficient proxy based change tracking at runtime:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;FONT color=#4e9c9c&gt;Product&lt;BR&gt;&lt;/FONT&gt;{&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; ProductID { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ProductName { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; SupplierID { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; QuantityPerUnit { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;decimal&lt;/SPAN&gt; UnitPrice { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;FONT color=#50a0a0&gt;InventoryDetail&lt;/FONT&gt; InventoryDetail { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; Discontinued { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;FONT color=#54a7a7&gt;Category &lt;/FONT&gt;Category { &lt;FONT color=#0000ff&gt;get&lt;/FONT&gt;; &lt;FONT color=#0000ff&gt;set&lt;/FONT&gt;; }&lt;BR&gt;}&lt;BR&gt;&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;Once again, keep in mind that you must use &lt;B&gt;CreateObject &lt;/B&gt;for creating proxy instances you want to then add or attach to the context. But pure POCO entities that don’t rely on proxies and proxy based entities can work together. You need to only use CreateObject when dealing with proxy based entities.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;What if I want both Deferred Loading and better change tracking for the same POCO type?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The two are not mutually exclusive and you don’t have to choose between a Deferred Loading proxy and a Change Tracking proxy. If you want Deferred Loading and efficient change tracking, you just have to follow the rules for Change Tracking via proxies, and enable Deferred Loading. Change Tracking proxies will give you deferred loading if deferred loading is enabled.&lt;/P&gt;
&lt;H4&gt;Explicit Loading&lt;/H4&gt;
&lt;P&gt;All this deferred loading capability is great – but there are plenty of you out there that want to be in full control of how you load related entities. You might even choose to go the route of pure POCO without having to resort to any of the automatic proxy generation done for you.&lt;/P&gt;
&lt;P&gt;This is a perfectly acceptable (and preferable in many cases) and you can use explicit loading of relationships and be in complete control of how you query for data from the database.&lt;/P&gt;
&lt;P&gt;There are two options for doing &lt;B&gt;Explicit Load&lt;/B&gt; with POCO:&lt;/P&gt;
&lt;P&gt;One is to use &lt;B&gt;ObjectContext.LoadProperty &lt;/B&gt;and specify the name of the navigation property you want to load:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;context.LoadProperty(beveragesCategory, &lt;SPAN style="COLOR: #006080"&gt;&lt;FONT color=#800000&gt;"Products"&lt;/FONT&gt;&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;This gets the job done – but it isn’t very type safe as you can see. If I don’t have the right name of the navigation property here, I will get a runtime exception.&lt;/P&gt;
&lt;P&gt;Some of you might actually prefer this:&lt;/P&gt;
&lt;DIV style="BORDER-BOTTOM: silver 1px solid; TEXT-ALIGN: left; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 4px; LINE-HEIGHT: 12pt; BACKGROUND-COLOR: #f4f4f4; MARGIN: 20px 0px 10px; PADDING-LEFT: 4px; WIDTH: 97.5%; PADDING-RIGHT: 4px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; MAX-HEIGHT: 200px; FONT-SIZE: 8pt; OVERFLOW: auto; BORDER-TOP: silver 1px solid; CURSOR: text; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 4px" id=codeSnippetWrapper&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;context.LoadProperty(beveragesCategory, c =&amp;gt; c.Products);&lt;/PRE&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;I can use a lambda expression to specify the property that I want to load explicitly, and this is offers more type safety.&lt;/P&gt;
&lt;P&gt;So that’s about everything I planned on covering in the second post. There’s more to come however – in the final part of this series, we’ll go over some of the things to be aware of when dealing with pure POCO (non proxy) instances and keeping things in sync between your object graph and the Object State Manager. We will also cover variations of SaveChanges that you might want to be aware of.&lt;/P&gt;
&lt;P&gt;In the meantime, check out the sample code that I have updated to cover some of the things we have talked about in this post.&lt;/P&gt;
&lt;P&gt;Faisal Mohamood &lt;BR&gt;Program Manager, Entity Framework&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9647609" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adonet/attachment/9647609.ashx" length="16340" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/adonet/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item><item><title>POCO in the Entity Framework: Part 1 - The Experience</title><link>http://blogs.msdn.com/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx</link><pubDate>Fri, 22 May 2009 03:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9634552</guid><dc:creator>dpblogs</dc:creator><slash:comments>42</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9634552.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9634552</wfw:commentRss><description>&lt;P&gt;Last week I mentioned in the &lt;A href="http://blogs.msdn.com/adonet/archive/2009/05/11/sneak-preview-persistence-ignorance-and-poco-in-entity-framework-4-0.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/05/11/sneak-preview-persistence-ignorance-and-poco-in-entity-framework-4-0.aspx"&gt;sneak preview on POCO&lt;/A&gt; that support for POCO entities is one of the new capabilities we have added to Entity Framework 4.0. This week, I’d like to go into the details of POCO support in Entity Framework 4.0.&lt;/P&gt;
&lt;P&gt;There’s quite a bit to discuss here, including:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Overall POCO experience in Entity Framework 4.0&lt;/LI&gt;
&lt;LI&gt;Change Tracking in POCO&lt;/LI&gt;
&lt;LI&gt;Relationship Fix-up&lt;/LI&gt;
&lt;LI&gt;Complex Types&lt;/LI&gt;
&lt;LI&gt;Deferred (Lazy) Loading and Explicit Loading&lt;/LI&gt;
&lt;LI&gt;Best Practices&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In this post, I will focus primarily on the overall experience so that you can get started with POCO in Entity Framework 4.0 right away. I’d like to use a simple example that we can walk through so you can see what it feels like to use POCO in Entity Framework 4.0. I will use the Northwind database, and&amp;nbsp; we’ll continue to build on this example in subsequent posts.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 1 – Create the Model, turn off default Code Generation&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;While POCO allows you to write your own entity classes in a persistence ignorant fashion, there is still the need for you to “plug in” persistence and EF metadata so that your POCO entities can be materialized from the database and persisted back to the database. In order to do this, you will still need to either create an Entity Data Model using the Entity Framework Designer or provide the CSDL, SSDL and MSL metadata files exactly as you have done with Entity Framework 3.5. So first I’ll generate an EDMX using the ADO.NET Entity Data Model Wizard.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_thumb.png" width=491 height=341 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a class library project for defining your POCO types. I named mine &lt;B&gt;NorthwindModel&lt;/B&gt;. This project will be persistence ignorant and will not have a dependency on the Entity Framework.&lt;/LI&gt;
&lt;LI&gt;Create a class library project that will contain your persistence aware code. I named mine &lt;B&gt;NorthwindData. &lt;/B&gt;This project will have a dependency on Entity Framework (System.Data.Entity) in addition to a dependency on the &lt;B&gt;NorthwindModel&lt;/B&gt; project.&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Add New Item &lt;/B&gt;to the &lt;B&gt;NorthwindData&lt;/B&gt; project and add an ADO.NET Entity Data Model called &lt;B&gt;Northwind.edmx &lt;/B&gt;(doing this will automatically add the dependency to the Entity Framework).&lt;/LI&gt;
&lt;LI&gt;Go through “Generate from Database” and build a model for the Northwind database. &lt;/LI&gt;
&lt;LI&gt;For now, select &lt;B&gt;Categories&lt;/B&gt; and &lt;B&gt;Products&lt;/B&gt; as the only two tables you are interested in adding to your Entity Data model.&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Now that I have my Entity Data model to work with, there is one final step before I start to write code : turn off code generation. After all you are interested in POCO – so remove the &lt;B&gt;Custom Tool &lt;/B&gt;that is responsible for generating &lt;B&gt;EntityObject&lt;/B&gt; based code for &lt;B&gt;Northwind.edmx. &lt;/B&gt;This will turn off code generation for your model.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_4.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_thumb_1.png" width=501 height=348 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/POCOintheEntityFrameworkPart1TheExperien_F9E4/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;We are now ready to write our POCO entities.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 2 – Code up your POCO entities&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;I am going to write simple POCO entities for Category and Product. These will be added to the &lt;B&gt;NorthwindModel&lt;/B&gt; project. Note that what I show here shouldn’t be taken as best practice and the intention here is to demonstrate the simplest case that works out of the box. We will extend and customize this to our needs as we go forward and build on top of this using &lt;B&gt;Repository&lt;/B&gt; and &lt;B&gt;Unit of Work&lt;/B&gt; patterns later on.&lt;/P&gt;
&lt;P&gt;Here’s sample code for our Category entity:&lt;/P&gt;&lt;PRE class=csharpcode&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; &lt;FONT color=#54a7a7&gt;Category&lt;/FONT&gt;
    {
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; CategoryID { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; CategoryName { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; Description { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;byte&lt;/SPAN&gt;[] Picture { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;FONT color=#5fafaf&gt;List&lt;FONT color=#000000&gt;&amp;lt;&lt;/FONT&gt;Product&lt;/FONT&gt;&amp;gt; Products { get; set; }
    }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;Note that I have defined properties for scalar properties as well as navigation properties in my model. The Navigation Property in our model translates to a List&amp;lt;Product&amp;gt;.&lt;/P&gt;
&lt;P&gt;Similarly, Product entity can be coded like this:&lt;/P&gt;&lt;PRE class=csharpcode&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; &lt;FONT color=#54a9a9&gt;Product&lt;/FONT&gt;
    {
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; ProductID { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; ProductName { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; SupplierID { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; QuantityPerUnit { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;decimal&lt;/SPAN&gt; UnitPrice { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;FONT color=#54a7a7&gt;Int16&lt;/FONT&gt; UnitsInStock { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;FONT color=#58abab&gt;Int16 &lt;/FONT&gt;UnitsOnOrder { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;FONT color=#54a9a9&gt;Int16&lt;/FONT&gt; ReorderLevel { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; Discontinued { get; set; }
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;FONT color=#5fafaf&gt;Category&lt;/FONT&gt; Category { get; set; }
    }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;In this case, since the relationship allows only one &lt;B&gt;Category&lt;/B&gt; that a &lt;B&gt;Product&lt;/B&gt; can belong to, we have a reference to a &lt;B&gt;Category&lt;/B&gt; (unlike the &lt;B&gt;List&amp;lt;T&amp;gt;&lt;/B&gt; collection we have for modeling the Navigation Property in &lt;B&gt;Category&lt;/B&gt;).&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 3 – Code up your Entity Framework Context&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The last thing I have to do in order to pull all of this together is to provide a context implementation (much like the &lt;B&gt;ObjectContext&lt;/B&gt; implementation you get when you use default code generation). The context is the glue that brings persistence awareness into your application, and it will allow you to compose queries, materialize entities as well as save changes back to the database. The context will be a part of the &lt;B&gt;NorthwindData&lt;/B&gt; project.&lt;/P&gt;
&lt;P&gt;For simplicity, I will include our context into the same class library that has our entity types – but when we discuss patterns such as &lt;B&gt;Repository &lt;/B&gt;and &lt;B&gt;Unit of Work&lt;/B&gt;, we will set it up such that you have a pure POCO class library without any persistence concerns.&lt;/P&gt;
&lt;P&gt;Here’s a simple context implementation for our scenario:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; &lt;FONT color=#5fafaf&gt;NorthwindContext &lt;FONT color=#000000&gt;:&lt;/FONT&gt; ObjectContext&lt;/FONT&gt;
    {   
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; NorthwindContext() : &lt;SPAN class=kwrd&gt;base&lt;/SPAN&gt;&lt;FONT color=#800000&gt;&lt;FONT color=#000000&gt;(&lt;/FONT&gt;"name=NorthwindEntities"&lt;/FONT&gt;&lt;FONT color=#000000&gt;,&lt;/FONT&gt; &lt;BR&gt;&lt;FONT color=#800000&gt;"NorthwindEntities"&lt;/FONT&gt;)  
        {
            _categories = CreateObjectSet&amp;lt;&lt;FONT color=#58abab&gt;Category&lt;/FONT&gt;&amp;gt;();
            _products = CreateObjectSet&amp;lt;&lt;FONT color=#50a0a0&gt;Product&lt;/FONT&gt;&amp;gt;();
        }

        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;FONT color=#59acac&gt;ObjectSet&lt;FONT color=#000000&gt;&amp;lt;&lt;/FONT&gt;Category&lt;/FONT&gt;&amp;gt; Categories
        {
            get 
            { 
                &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; _categories; 
            }
        }
        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;FONT color=#59acac&gt;ObjectSet&lt;FONT color=#000000&gt;&amp;lt;&lt;/FONT&gt;Category&lt;/FONT&gt;&amp;gt; _categories;

        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;FONT color=#59acac&gt;ObjectSet&lt;/FONT&gt;&amp;lt;&lt;FONT color=#50a0a0&gt;Product&lt;/FONT&gt;&amp;gt; Products
        {
            get
            {
                &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; _products;
            }
        }
        &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;FONT color=#59acac&gt;ObjectSet&lt;/FONT&gt;&amp;lt;&lt;FONT color=#50a0a0&gt;Product&lt;/FONT&gt;&amp;gt; _products;
    }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;Note that &lt;B&gt;ObjectSet&lt;/B&gt;&amp;lt;&lt;B&gt;T&lt;/B&gt;&amp;gt; is a more specialized &lt;B&gt;ObjectQuery&lt;/B&gt;&amp;lt;&lt;B&gt;T&lt;/B&gt;&amp;gt; that we introduced in Entity Framework 4.0.&lt;/P&gt;
&lt;P&gt;That’s it – now you have pure POCO entities with a simple context that will allow you to write queries like this:&lt;/P&gt;&lt;PRE class=csharpcode&gt;   &lt;FONT color=#52a3a3&gt; NorthwindContext&lt;/FONT&gt; db = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; &lt;FONT color=#4e9a9a&gt;NorthwindContext&lt;/FONT&gt;();

    &lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; beverages = &lt;FONT color=#0000ff&gt;from&lt;/FONT&gt; p &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; db.Products
                    &lt;SPAN class=kwrd&gt;where&lt;/SPAN&gt; p.Category.CategoryName == &lt;SPAN class=str&gt;&lt;FONT color=#800000&gt;"Beverages"&lt;/FONT&gt;&lt;/SPAN&gt;
                    &lt;FONT color=#0000ff&gt;select&lt;/FONT&gt; p;&lt;/PRE&gt;
&lt;P&gt;The entities that are materialized are pure POCO entities, and you can make and persist changes much like you would with regular &lt;B&gt;EntityObject&lt;/B&gt; or &lt;B&gt;IPOCO&lt;/B&gt; entities. You get all the services provided by Entity Framework - the only difference is that you are using pure POCO entities.&lt;/P&gt;
&lt;P&gt;There are many possibilities here as far as how we can improve on this simplified example. Before we get into that however, I would like to get some basic questions out of the way.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Do I need an Entity Data Model before I can use POCO?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Yes – POCO support in Entity Framework 4.0 simply removes the need of having persistence specific concerns in your entity classes. There is still the need for you to have a CSDL/SSDL/MSL (collectively EDMX) metadata so that the Entity Framework is able to use your entities along with the metadata in order to enable data access. There is a separate effort that we are working on that will allow you to do true “code-first” development without the need to have a predefined EDMX model. A community preview of this feature will be released to the web in the coming months. We will roll this into the product the first chance we get. As always, your feedback will be helpful.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Do I have to always hand-craft these entities and the context?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;No – there is a very powerful and flexible code generation mechanism in Entity Framework 4.0 that is based on T4 as Alex blogged about &lt;A href="http://blogs.msdn.com/adonet/archive/2009/05/19/sneak-peek-using-code-generation-templates-with-the-entity-framework-4-0.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/05/19/sneak-peek-using-code-generation-templates-with-the-entity-framework-4-0.aspx"&gt;here&lt;/A&gt;. You can provide your own templates that allow you to build your entities in a way that you see fit. We are also working on providing standard out of the box templates that will generate POCO entities for you.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;How is metadata mapped when using POCO entities?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;In Entity Framework 3.5, both &lt;B&gt;EntityObject&lt;/B&gt; and &lt;B&gt;IPOCO&lt;/B&gt; based entities relied on the use of mapping attributes that were meant for decorating and mapping the entity types and properties back to the corresponding elements in the Conceptual model. Entity Framework 4.0 introduces convention based mapping for allowing mapping of Entity Types, Properties, Complex Types and Relationships back to the conceptual model without the need for explicit decoration. The simple rule here is that Entity Type names, Property names and Complex Types names used in your POCO classes must match those defined by the conceptual model. Namespace names are ignored and don’t have to match between the class definition and the conceptual model.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Do I need to have public getters and setters for all properties in my entity classes?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;You can use any access modifier on your POCO type’s properties as long as none of the mapped properties are virtual and as long as you don’t require partial trust support. When running in partial trust, there are specific requirements on the visibility of access modifiers on your entity classes. We will be documenting the complete set of access modifiers that are supported when partial trust is involved.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;What types of collections are supported for collection based navigation properties?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Any collection that is an &lt;B&gt;ICollection&amp;lt;T&amp;gt;&lt;/B&gt; will be supported. If you don’t initialize the field with a concrete type that is an &lt;B&gt;ICollection&amp;lt;T&amp;gt;&lt;/B&gt; type, then an &lt;B&gt;List&amp;lt;T&amp;gt;&lt;/B&gt; type will be provided upon materialization.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Can I have uni-directional relationships? For instance – I would like to have a Category property in my Product class, but I don’t want to have a Products collection in my Category class.&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Yes – this is supported. The only restriction here is that your entity types have to reflect what is defined by the model. If you are not interested in having the navigation property for one side of the relationship, then remove it from the model completely.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Is Deferred (Lazy) Loading supported with POCO?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Yes – Deferred (Lazy) loading is supported with POCO through the use of proxy types that are used to provide automatic lazy loading behavior on top of your POCO classes. This is something that we’ll cover when we get to deferred loading – until then know that eager loading via the use of “&lt;B&gt;Include&lt;/B&gt;” is also supported, like so:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;FONT color=#0000ff&gt;var&lt;/FONT&gt; beverageCategory = (&lt;FONT color=#0000ff&gt;from&lt;/FONT&gt; c &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; context.Categories&lt;BR&gt;.Include(&lt;SPAN class=str&gt;&lt;FONT color=#800000&gt;"Products"&lt;/FONT&gt;&lt;/SPAN&gt;)
                        &lt;SPAN class=kwrd&gt;where&lt;/SPAN&gt; c.CategoryName == &lt;SPAN class=str&gt;&lt;FONT color=#800000&gt;"Beverages"&lt;/FONT&gt;&lt;/SPAN&gt;
                        &lt;FONT color=#0000ff&gt;select&lt;/FONT&gt; c).Single();&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;If I were to use Deferred (Lazy) Loading, I don’t have to do this – we’ll discuss that when we discuss proxies.&lt;/P&gt;
&lt;H4&gt;Fixing up Relationships&lt;/H4&gt;
&lt;P&gt;There are two types of fix-ups to be aware of: 1)Fix-up during query, and 2) Fix-up during changes to your entities/relationships&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Fix-up during Query&lt;/U&gt;&lt;/B&gt;&lt;U&gt; &lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Fix-up during query happens when you load related entities using separate queries on the same &lt;B&gt;ObjectContext&lt;/B&gt;. For instance, if I were to query for a category instance &lt;B&gt;Beverages&lt;/B&gt;, and later query for a product instance &lt;B&gt;Chai&lt;/B&gt; (that is in Category &lt;B&gt;Beverages&lt;/B&gt;), I would want &lt;B&gt;chai.Category&lt;/B&gt; to point to the instance of the &lt;B&gt;Beverages&lt;/B&gt; category without additional work.&lt;/P&gt;
&lt;P&gt;This is automatic and works today.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Fix-up during changes to your entities/relationships&lt;/U&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;This is the relationship fix-up between two entities when I add/remove an entity that is related to another entity or alter relationships. Think of this as the case when I create a new product called &lt;B&gt;“Diet Chai”&lt;/B&gt; and want to associate it with the &lt;B&gt;Beverages &lt;/B&gt;category&lt;B&gt;.&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;In Beta1 of Entity Framework 4.0, you do not get automatic relationship fix-up in this case with POCO entities. When dealing with relationships that change between entities, you will have to make sure that your POCO types include the logic to manage fix-up on both ends of the relationship correctly. &lt;/P&gt;
&lt;P&gt;For instance, in my Northwind example, I have defined the following method on &lt;B&gt;Category&lt;/B&gt; to support adding / removing of Orders.&lt;/P&gt;&lt;PRE class=csharpcode&gt;        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; AddProduct(&lt;FONT color=#54a7a7&gt;Product&lt;/FONT&gt; p)
        {
            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (Products == &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;)
            {
                Products = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; &lt;FONT color=#4e9a9a&gt;List&lt;FONT color=#000000&gt;&amp;lt;&lt;/FONT&gt;Product&lt;/FONT&gt;&amp;gt;();
            }

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (!Products.Contains(p))
            {
                Products.Add(p);
            }            
            
            p.Category = &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;;
        }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;In general, it is good to use a pattern like this to support adding/removing related items rather than using the relationship collection to add/remove related entities. You also have options of making the getter/setter for the actual EF backed collection private/internal to support more fine grained access – but as mentioned earlier, some of this depends on the requirements as to whether you require partial trust support or not.&lt;/P&gt;
&lt;P&gt;So we have covered quite a bit of ground in this “quick look” at the overall POCO experience. There’s quite a lot more to talk about – and I will be continuing this discussion early next week. In the meantime, take a look at the complete solution (attached) if you are interested in the sample code covering all the concepts we covered here. Please keep in mind that you must have a local instance of Northwind database installed on the machine where you are running this sample.&lt;/P&gt;
&lt;P&gt;In my next post we will look at Complex Types, Change Tracking, Proxies, Lazy Loading and Eager Loading. Until then, please look through the MSDN Documentation on POCO &lt;A href="http://msdn.microsoft.com/en-us/library/dd456853(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd456853(VS.100).aspx"&gt;here&lt;/A&gt; for more details on POCO support in Entity Framework 4.0.&lt;/P&gt;
&lt;P&gt;Let us know what you think!&lt;/P&gt;
&lt;P&gt;Faisal Mohamood &lt;BR&gt;Program Manager, Entity Framework&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9634552" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adonet/attachment/9634552.ashx" length="20480" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx">Entity Framework</category></item></channel></rss>