<?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 : EDM</title><link>http://blogs.msdn.com/adonet/archive/tags/EDM/default.aspx</link><description>Tags: EDM</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Sneak Preview: Model Defined Functions</title><link>http://blogs.msdn.com/adonet/archive/2009/05/14/sneak-preview-model-defined-functions.aspx</link><pubDate>Thu, 14 May 2009 22:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9617236</guid><dc:creator>dpblogs</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9617236.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9617236</wfw:commentRss><description>&lt;p&gt;Model Defined Functions is a new feature coming in .NET 4.0. They are similar to SqlServer Table Value Functions because they are composable, so you can layer function calls and queries. The key difference is that they are declared in terms of the conceptual model, rather than the storage model so they are defined in eSQL not T-SQL.&lt;/p&gt;
&lt;p&gt;Model Defined Functions are useful if you want to encapsulate some commonly used eSQL in a function, for example something that calculates a person’s age.&lt;/p&gt;
&lt;p&gt;To create a function that does that all you do is add something like this to the CSDL under the Schema element.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="GetAge"&lt;/span&gt; &lt;span class="attr"&gt;ReturnType&lt;/span&gt;&lt;span class="kwrd"&gt;="Edm.Int32"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Parameter&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Person"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="Model.Person"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DefiningExpression&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;           Edm.DiffYears(Edm.CurrentDateTime(), Person.Birthday)&lt;br&gt;     &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DefiningExpression&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Notice that the DefiningExpression can be any valid eSQL expression that matches the expected ReturnType. Parameters, like Person, are referenced directly in the eSQL by name, without an @ symbol.&lt;/p&gt;
&lt;p&gt;With this definition in place you can use it in eSQL queries immediately like this: 
&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;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;span class="kwrd"&gt;VALUE&lt;/span&gt;(P) &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [MyEntityContainer].[People] &lt;br&gt;&lt;span class="kwrd"&gt;AS&lt;/span&gt; P &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; Namespace.GetAge(P) &amp;gt; 35 &lt;/pre&gt;
&lt;p&gt;If you want to use the function in LINQ you need to have a corresponding CLR method that you can call. Essentially this is just a method stub too, something that has the same type signature, i.e. a function that takes a Person and returns an int.&lt;/p&gt;&lt;pre class="csharpcode"&gt;[&lt;font color="#50a0a0"&gt;EdmFunction&lt;/font&gt;("Namespace", "GetAge")]&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; GetAge(&lt;font color="#4f9d9d"&gt;Person&lt;/font&gt; p)&lt;br&gt;{ &lt;br&gt;    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;font color="#55aaaa"&gt;NotSupportedException&lt;/font&gt;(…);&lt;br&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;Here the EdmFunction attribute allows the Entity Framework to map calls to this function in a LINQ expression back to the Model Defined Function.&lt;/p&gt;
&lt;p&gt;With this in place the Entity Framework can translate the LINQ query below into something that can run &lt;u&gt;completely&lt;/u&gt; in the database.&lt;/p&gt;&lt;pre class="csharpcode"&gt;var results = from person &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.People&lt;br&gt;              &lt;span class="kwrd"&gt;where&lt;/span&gt; GetAge(person) &amp;gt; 35&lt;br&gt;              select person;&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;This simple example barely scratches the surface of the sorts of things you can do with Model Defined Functions. &lt;/p&gt;
&lt;p&gt;Look out for a more in depth post on Model Defined Functions soon.&lt;/p&gt;
&lt;p&gt;- &lt;a href="http://blogs.msdn.com/alexj" mce_href="http://blogs.msdn.com/alexj"&gt;&lt;b&gt;Alex James&lt;/b&gt;&lt;/a&gt; &lt;br&gt;Program Manager, Entity Framework&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9617236" 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/EDM/default.aspx">EDM</category></item><item><title>Sneak Preview: Model First in the Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-model-first-in-the-entity-framework-4-0.aspx</link><pubDate>Wed, 13 May 2009 01:52:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9608343</guid><dc:creator>dpblogs</dc:creator><slash:comments>24</slash:comments><comments>http://blogs.msdn.com/adonet/comments/9608343.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=9608343</wfw:commentRss><description>&lt;p&gt;An exciting new Entity Framework Designer feature in Visual Studio 2010 is the ability to generate DDL that will create a database that can store your entity data model. This feature is not only exciting because it brings a long overdue capability to life, but because it is fully extensible: You can take control of the entire process, or plug into parts of it. For example, you can take over the DDL generation step to add support for your database of choice, or to customize the DDL generation process. Alternatively, you can take over the inheritance mapping step and replace our out-of-the box strategy (which is table-per-type) with your own. Or take over the entire mechanism and generate both stored procedure mappings and CRUD stored procedures for all your types. In a future post, we will show you exactly how to do this and provide an implementation of the table-per-hierarchy mapping for you to use or modify.&lt;/p&gt;  &lt;p&gt;For now, let’s take a quick look at this feature by taking a very simple model:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/SneakPreviewModelFirstintheEntityFrame.0_DC61/clip_image002_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/SneakPreviewModelFirstintheEntityFrame.0_DC61/clip_image002_thumb.jpg" width="513" height="378" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;We right click…and in the context menu we see, and click on, “Generate Database Script from Model”:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/SneakPreviewModelFirstintheEntityFrame.0_DC61/clip_image002%5B7%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[7]" border="0" alt="clip_image002[7]" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/SneakPreviewModelFirstintheEntityFrame.0_DC61/clip_image002%5B7%5D_thumb.jpg" width="308" height="143" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The database generation wizard asks for a database to target. This information is used by the wizard to determine which database-specific types to translate the Entity Data Model (EDM) types to, and how to render DDL that is appropriate for the target database. In this case, I just created a new Microsoft SQL Server database file:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/SneakPreviewModelFirstintheEntityFrame.0_DC61/clip_image002%5B9%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[9]" border="0" alt="clip_image002[9]" src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/SneakPreviewModelFirstintheEntityFrame.0_DC61/clip_image002%5B9%5D_thumb.jpg" width="493" height="481" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Once we click on next, we are shown a preview of the generated DDL, which will be saved to disk once we click on “Finish”. Here is an excerpt from the DDL generated now for SQL Server:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;…
&lt;span class="rem"&gt;-- Creating table 'IngredientSet_Protien'&lt;/span&gt;
&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[IngredientSet_Protien] (
    [Cut] nvarchar(100)  &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [Type] nvarchar(70)  &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [Id] &lt;span class="kwrd"&gt;int&lt;/span&gt;  &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;
);
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
&lt;span class="rem"&gt;-- Creating table 'IngredientSet_Plant'&lt;/span&gt;
&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[IngredientSet_Plant] (
    [IsFruit] &lt;span class="kwrd"&gt;bit&lt;/span&gt;  &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [IsHerb] &lt;span class="kwrd"&gt;bit&lt;/span&gt;  &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [IsVegetable] &lt;span class="kwrd"&gt;bit&lt;/span&gt;  &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [Id] &lt;span class="kwrd"&gt;int&lt;/span&gt;  &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;
);
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="rem"&gt;-- --------------------------------------------------&lt;/span&gt;
&lt;span class="rem"&gt;-- Creating all Primary Key Constraints&lt;/span&gt;
&lt;span class="rem"&gt;-- --------------------------------------------------&lt;/span&gt;

&lt;span class="rem"&gt;-- Creating primary key on [Id] in table 'RecipeSet'&lt;/span&gt;
&lt;span class="kwrd"&gt;ALTER&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[RecipeSet] &lt;span class="kwrd"&gt;WITH&lt;/span&gt; &lt;span class="kwrd"&gt;NOCHECK&lt;/span&gt;
&lt;span class="kwrd"&gt;ADD&lt;/span&gt; &lt;span class="kwrd"&gt;CONSTRAINT&lt;/span&gt; [PK_RecipeSet]
    &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt; ([Id] &lt;span class="kwrd"&gt;ASC&lt;/span&gt;)
    &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
…
&lt;span class="rem"&gt;-- --------------------------------------------------&lt;/span&gt;
&lt;span class="rem"&gt;-- Creating all Foreign Key Constraints&lt;/span&gt;
&lt;span class="rem"&gt;-- --------------------------------------------------&lt;/span&gt;

&lt;span class="rem"&gt;-- Creating foreign key on [Chef_Id] in table 'RecipeSet'&lt;/span&gt;
&lt;span class="kwrd"&gt;ALTER&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[RecipeSet] &lt;span class="kwrd"&gt;WITH&lt;/span&gt; &lt;span class="kwrd"&gt;NOCHECK&lt;/span&gt;
&lt;span class="kwrd"&gt;ADD&lt;/span&gt; &lt;span class="kwrd"&gt;CONSTRAINT&lt;/span&gt; [FK_ChefRecipe]
    &lt;span class="kwrd"&gt;FOREIGN&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; ([Chef_Id])
    &lt;span class="kwrd"&gt;REFERENCES&lt;/span&gt; [dbo].[ChefSet]
        ([Id])
    &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;DELETE&lt;/span&gt; &lt;span class="kwrd"&gt;NO&lt;/span&gt; &lt;span class="kwrd"&gt;ACTION&lt;/span&gt; &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;UPDATE&lt;/span&gt; &lt;span class="kwrd"&gt;NO&lt;/span&gt; &lt;span class="kwrd"&gt;ACTION&lt;/span&gt;
…&lt;/pre&gt;

&lt;p&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;

&lt;p&gt;Note here that the default inheritance mapping strategy is to create a table for all subtypes: In the above DDL, you can see that we are generating tables for the Protien and Plant subtypes. These tables are named with the name of the EntitySet in which the types live, to which we append the name of the type itself.&lt;/p&gt;

&lt;p&gt;Note also that we generate primary and foreign key constraints for the model.&lt;/p&gt;

&lt;p&gt;Watch for our in-depth series on Model First with the Entity Framework that we are working on publishing in the coming weeks.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;- Noam Ben-Ami
  &lt;br /&gt;Program Manager, Entity Framework&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9608343" 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/EDM/default.aspx">EDM</category></item><item><title>Update Model – a Question of Identity – Part 2 of 3</title><link>http://blogs.msdn.com/adonet/archive/2008/07/22/update-model-a-question-of-identity-part-2-of-3.aspx</link><pubDate>Tue, 22 Jul 2008 19:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8764364</guid><dc:creator>dpblogs</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/adonet/comments/8764364.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=8764364</wfw:commentRss><description>&lt;P&gt;This article is Part 2 of 3 – please see &lt;A href="http://blogs.msdn.com/adonet/archive/2008/07/21/update-model-a-question-of-identity-part-1-of-3.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/07/21/update-model-a-question-of-identity-part-1-of-3.aspx"&gt;http://blogs.msdn.com/adonet/archive/2008/07/21/update-model-a-question-of-identity-part-1-of-3.aspx&lt;/A&gt; for Part 1.&lt;/P&gt;
&lt;P&gt;In the last article I explained the principle that the C-side updates would be non-destructive.&lt;/P&gt;
&lt;P&gt;The “Update Model” code needs to decide when we should add new C-side EntityTypes, new C-side Properties and new C-side Associations. This brings us into the idea of identity. Bear with me – this can get pretty complicated.&lt;/P&gt;
&lt;P&gt;Suppose you have a database with two tables in it. They have the same name but are in different schemas e.g. schema1.Customer and schema2.Customer. All S-side EntitySets (which are the way the EDM represents a database table or view) in a given model must have unique names. So if you attempt to import both of the above tables then one of them will be represented as an EntitySet with name ‘Customer’ and one with name ‘Customer1’ each with a matching EntityType. Which one will be which? Well, it depends on in what order you import them and sometimes on what else you import at the same time. The important point is that the Name attribute of the EntitySet is not always the same as the name of underlying database object.&lt;/P&gt;
&lt;P&gt;So we cannot rely on the Name attribute of a given EntitySet to identify the underlying database object. But for “Update Model from Database” we do need to identify what the true underlying database object is to decide whether a given one is “new”. So instead we construct a “database identity” for each S-side EntitySet which consists of its underlying schema name and its underlying table/view name. If the EntitySet’s Name attribute does not match the underlying table/view name then either a Table attribute or the special attribute store:Name (where ‘store’ is a prefix defined as the XML namespace “http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator”) is defined on that EntitySet. The value of this attribute is the true underlying database object name. Similarly the Schema or store schema attribute will represent the true underlying database schema name (and there’s a similar story for Function elements which is how the EDM represents stored procedures).&lt;/P&gt;
&lt;P&gt;This combination of the true database schema name and the true database object name are the “database identity” of that EntitySet. “New” S-side EntitySets are defined as those whose “database identity” does not appear in the S-side of the existing model.&lt;/P&gt;
&lt;P&gt;For every imported, new S-side EntitySet we create a single, matching C-side EntitySet and EntityType and the mappings necessary to map them through to the S-side EntitySet. If it is available, we will use the existing S-side name for the matching C-side EntityType, but that name may already be in use in which case we will try appending 1, 2, 3 … until we find a name that is not in use.&lt;/P&gt;
&lt;P&gt;So as an example, if a C-side EntityType, say ‘Customer’, was originally mapped to the S-side ‘Customer’ EntityType but has been manually unmapped, and “Update Model from Database” is run then the above rules will _not_ result in a “duplicate” C-side EntityType called ‘Customer1’ because “Update Model” knows that there was already a ‘Customer’ S-side EntityType – we assume the user knew what s/he was doing when they unmapped the C-side EntityType. However if a _new_ S-side EntityType called ‘Customer’ is added and there happens to exist a C-side EntitySet already called ‘Customer’ then the new, matching C-side EntityType would be called ‘Customer1’ and it will be up to the user to rename the C-side EntityTypes as needed.&lt;/P&gt;
&lt;P&gt;In the next article I’ll explain how this concept is extended to C-side Properties and Associations.&lt;/P&gt;
&lt;P&gt;Lawrence Jones &lt;BR&gt;Software Design Engineer, Entity Framework Tools&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8764364" 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/EDM/default.aspx">EDM</category></item><item><title>Update Model – a Question of Identity – Part 1 of 3</title><link>http://blogs.msdn.com/adonet/archive/2008/07/21/update-model-a-question-of-identity-part-1-of-3.aspx</link><pubDate>Mon, 21 Jul 2008 21:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8762197</guid><dc:creator>dpblogs</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/adonet/comments/8762197.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=8762197</wfw:commentRss><description>&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I propose to explain the reason behind some of the oddities of the “Update Model from Database” functionality and hopefully answer some common questions that come up about it.&lt;/P&gt;
&lt;P&gt;Before I get started let me note that this will be a fairly technical post split into three parts (I’ll post links to the other parts as responses to this one). There is also a good blog on this subject taking a look at the changes since our last release and showcasing some particular examples of the principles I will be explaining below. This blog is by Noam Ben-Ami at the following link: &lt;A href="http://blogs.msdn.com/adonet/archive/2008/04/01/update-model-from-db.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/04/01/update-model-from-db.aspx"&gt;http://blogs.msdn.com/adonet/archive/2008/04/01/update-model-from-db.aspx&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;An EDMX file represents the conceptual (C-) side of the model, the storage (S-) side of the model and a mapping between the two. The major job of “Update Model from Database” is to update the S-side of the model to be consistent with any changes that have been made to the database since it was created or last updated. (Note that in this sense “changes” can also include any database objects which you chose not to include in your S-side model the last time through). “Update Model” will also automatically remove any mappings which would target non-existent S-side objects after the update.&lt;/P&gt;
&lt;P&gt;For RTM, the S-side of the model is completely replaced by a new S-side model generated from all the tables/views/stored procedures in the existing model plus any new ones selected via the “Update Model from Database” wizard. This has the advantage of ensuring that the new S-side model is self-consistent, but has the disadvantage that it removes any S-side elements which have been added by hand to the EDMX file. We are considering alternatives to this approach for V2.&lt;/P&gt;
&lt;P&gt;Now before we go on note that the Entity Designer shows you only the C-side of your model, not the S-side. The S-side is only visible through the Browser and entries in the Mapping Details window. Hence most people’s view of “the model” is the C-side of the model.&lt;/P&gt;
&lt;P&gt;Note also that for any given S-side model there are many possible C-side models which could be mapped to it: in particular in addition to the more simple 1:1 scenario, two or more C-side EntityTypes can be mapped to the same underlying table, or a single C-side EntityType can be mapped to more than one table.&lt;/P&gt;
&lt;P&gt;Although the major job of “Update Model from Database” is to update the S-side, we decided that, in order to reduce work for the user, we would also update the C-side but only under the following rule:&lt;/P&gt;
&lt;P&gt;· The C-side updates would be non-destructive.&lt;/P&gt;
&lt;P&gt;This means that we feel free to e.g. add new C-side EntityTypes to represent new S-side EntityTypes or new C-side Properties to represent new S-side Properties, but we will not e.g. delete a C-side EntityType because we believe the S-side EntityType it was mapped to has been deleted. Nor will we “resurrect” a C-side EntityType which the user has chosen to delete. We leave such decisions up to the user. &lt;/P&gt;
&lt;P&gt;As a consequence of this it is possible that an Entity Data Model which passed validation before “Update Model” was run will no longer be valid after “Update Model” is run. In this case the user should investigate each error message in the Error List Window and manually take some action to update the model before it can be used. The action that needs to be taken is probably destructive and so we leave it up to the user to decide.&lt;/P&gt;
&lt;P&gt;In the next article I’ll explain how “Update Model” makes the decision to create new C-side EntitySets based on new S-side EntitySets and what “identity” has to do with all this.&lt;/P&gt;
&lt;P&gt;Lawrence Jones &lt;BR&gt;Software Design Engineer, Entity Framework Tools&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8762197" 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/EDM/default.aspx">EDM</category></item><item><title>EDM Tools | Options (Part 3 of 4)</title><link>http://blogs.msdn.com/adonet/archive/2008/06/26/edm-tools-options-part-3-of-4.aspx</link><pubDate>Fri, 27 Jun 2008 00:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8658447</guid><dc:creator>dpblogs</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/adonet/comments/8658447.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=8658447</wfw:commentRss><description>&lt;H4&gt;Introduction&lt;/H4&gt;
&lt;P&gt;In &lt;A href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-1-of-4.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-1-of-4.aspx"&gt;parts one&lt;/A&gt; and &lt;A href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-2-of-4.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-2-of-4.aspx"&gt;two&lt;/A&gt; of this four-part series, we discussed the file differences between EDMX &amp;amp; csdl, ssdl &amp;amp; msl files, and we looked at the model &amp;amp; code generation APIs available in the .Net Runtime. In Part three, we discuss validation of EDM models, and we look at view generation for EDM models. 
&lt;H4&gt;Model Validation&lt;/H4&gt;
&lt;P&gt;The Visual Studio experience validates your EDMX models during a build, whenever an EDMX file is saved, and whenever a user selects the “Validate” context menu in the EDM designer. To validate a model from the command-line, you can execute the following command: 
&lt;P&gt;edmGen.exe /mode:ValidateArtifacts /incsdl:SqlCENorthwind.csdl /inssdl:SqlCENorthwind.ssdl /inmsl:SqlCENorthwind.msl 
&lt;P&gt;The code to programmatically validate a model defined in an EDMX file is shown in Listing 1. Here, we load the ssdl, csdl &amp;amp; msl into &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.edmitemcollection.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.edmitemcollection.aspx"&gt;EdmItemCollection&lt;/A&gt; instances. The process of loading these returns a list of errors that we can output. We then compile the mappings, which does a semantic validation to ensure that the mappings are correct for the EDM. 
&lt;P&gt;To programmatically validate a model, you can do the following:&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;private static void &lt;FONT color=#000000&gt;Validate(&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FileInfo &lt;FONT color=#000000&gt;edmxFile)
        {&lt;/FONT&gt;
            XDocument &lt;FONT color=#000000&gt;doc =&lt;/FONT&gt; XDocument&lt;FONT color=#000000&gt;.Load(edmxFile.FullName);&lt;/FONT&gt;
            XElement &lt;FONT color=#000000&gt;c = GetCsdlFromEdmx(doc);&lt;/FONT&gt;
            XElement &lt;FONT color=#000000&gt;s = GetSsdlFromEdmx(doc);&lt;/FONT&gt;
            XElement &lt;FONT color=#000000&gt;m = GetMslFromEdmx(doc);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// load the csdl
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;FONT color=#000000&gt;[] cReaders = { c.CreateReader() };&lt;/FONT&gt;
            IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;cErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EdmItemCollection &lt;FONT color=#000000&gt;edmItemCollection =&lt;/FONT&gt; 
                MetadataItemCollectionFactory&lt;FONT color=#000000&gt;.CreateEdmItemCollection(cReaders,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;out &lt;FONT color=#000000&gt;cErrors);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// load the ssdl 
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;FONT color=#000000&gt;[] sReaders = { s.CreateReader() };&lt;/FONT&gt;
            IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;sErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StoreItemCollection &lt;FONT color=#000000&gt;storeItemCollection =&lt;/FONT&gt; 
                MetadataItemCollectionFactory&lt;FONT color=#000000&gt;.CreateStoreItemCollection(sReaders,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;out &lt;FONT color=#000000&gt;sErrors);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// load the msl
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;FONT color=#000000&gt;[] mReaders = { m.CreateReader() };&lt;/FONT&gt;
            IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;mErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StorageMappingItemCollection &lt;FONT color=#000000&gt;mappingItemCollection =&lt;/FONT&gt; 
                MetadataItemCollectionFactory&lt;FONT color=#000000&gt;.CreateStorageMappingItemCollection(
                edmItemCollection, storeItemCollection, mReaders,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;out &lt;FONT color=#000000&gt;mErrors);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// validate the mappings
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;viewGenerationErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            &lt;FONT color=#000000&gt;viewGenerationErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EntityViewGenerator&lt;FONT color=#000000&gt;.Validate(mappingItemCollection);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// write errors
            &lt;FONT color=#000000&gt;WriteErrors(cErrors);
            WriteErrors(sErrors);
            WriteErrors(mErrors);
            WriteErrors(viewGenerationErrors);&lt;/FONT&gt;
        &lt;FONT color=#000000&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;B&gt;Listing 1. &lt;/B&gt;Code example to validate an EDMX file. Full code can be downloaded &lt;A href="http://code.msdn.microsoft.com/EdmGen2" mce_href="http://code.msdn.microsoft.com/EdmGen2"&gt;here&lt;/A&gt;. 
&lt;H4&gt;Generating Views&lt;/H4&gt;
&lt;P&gt;The Entity Framework runtime reasons about your data model via ESql Views. The runtime will generate and cache views if they aren’t included in your assembly, so there is no need to pre-generate the views. However, view-generation can be expensive. Pre-generating views and compiling them into your assembly may eliminate some of your application’s start-up costs. Inside of Visual Studio, we don’t do anything with the pre-generating views, but views can be generated using &lt;A href="http://msdn.microsoft.com/en-us/library/bb387165.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb387165.aspx"&gt;EdmGen.exe&lt;/A&gt; with the following command: 
&lt;P&gt;edmGen.exe /mode:ViewGeneration /incsdl:SqlCENorthwind.csdl /language:CSharp /outviews:views.cs /inmsl:SqlCENorthwind.msl /inssdl:SqlCENorthwind.ssdl 
&lt;P&gt;The views are output as ESql queries in a C# or VB file. After running the above example, the file views.cs will contain the views, and views.cs will need to be compiled into your assembly. 
&lt;P&gt;The code in Listing 2 below illustrates programmatically generating views given an EDMX file. You’ll note that the code below is very similar to the validation code in Listing 1. This is because the data structures built during validation are needed to perform view-compilation. In fact, the only difference between the validation and view generation is that view generation will output the views to a file. &lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;private static void &lt;FONT color=#000000&gt;ValidateAndGenerateViews(&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FileInfo &lt;FONT color=#000000&gt;edmxFile,&lt;/FONT&gt; LanguageOption &lt;FONT color=#000000&gt;languageOption)&lt;/FONT&gt;
        {
            XDocument &lt;FONT color=#000000&gt;doc =&lt;/FONT&gt; XDocument&lt;FONT color=#000000&gt;.Load(edmxFile.FullName);&lt;/FONT&gt;
            XElement &lt;FONT color=#000000&gt;c = GetCsdlFromEdmx(doc);&lt;/FONT&gt;
            XElement &lt;FONT color=#000000&gt;s = GetSsdlFromEdmx(doc);&lt;/FONT&gt;
            XElement &lt;FONT color=#000000&gt;m = GetMslFromEdmx(doc);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// load the csdl
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;FONT color=#000000&gt;[] cReaders = { c.CreateReader() };&lt;/FONT&gt;
            IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;cErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EdmItemCollection &lt;FONT color=#000000&gt;edmItemCollection =&lt;/FONT&gt; 
                MetadataItemCollectionFactory&lt;FONT color=#000000&gt;.CreateEdmItemCollection(cReaders, &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;SPAN style="COLOR: blue"&gt;out&lt;/SPAN&gt; &lt;FONT color=#000000&gt;cErrors);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// load the ssdl 
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;FONT color=#000000&gt;[] sReaders = { s.CreateReader() };&lt;/FONT&gt;
            IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;sErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StoreItemCollection &lt;FONT color=#000000&gt;storeItemCollection =&lt;/FONT&gt; 
                MetadataItemCollectionFactory&lt;FONT color=#000000&gt;.CreateStoreItemCollection(sReaders,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;out &lt;FONT color=#000000&gt;sErrors);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// load the msl
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;FONT color=#000000&gt;[] mReaders = { m.CreateReader() };&lt;/FONT&gt;
            IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;mErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StorageMappingItemCollection &lt;FONT color=#000000&gt;mappingItemCollection =&lt;/FONT&gt; 
                MetadataItemCollectionFactory&lt;FONT color=#000000&gt;.CreateStorageMappingItemCollection(
                edmItemCollection, storeItemCollection, mReaders,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;out &lt;FONT color=#000000&gt;mErrors);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// generate views &amp;amp; write them out to a file
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IList&amp;lt;EdmSchemaError&amp;gt; &lt;FONT color=#000000&gt;viewGenerationErrors =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;null;
            string &lt;FONT color=#000000&gt;outputFile =
                GetFileNameWithNewExtension(edmxFile,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;".GeneratedViews" &lt;FONT color=#000000&gt;+
                    GetFileExtensionForLanguageOption(languageOption));&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EntityViewGenerator &lt;FONT color=#000000&gt;evg =&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EntityViewGenerator&lt;FONT color=#000000&gt;(languageOption);
            viewGenerationErrors =
                evg.GenerateViews(mappingItemCollection, outputFile);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// write errors
            &lt;FONT color=#000000&gt;WriteErrors(cErrors);
            WriteErrors(sErrors);
            WriteErrors(mErrors);
            WriteErrors(viewGenerationErrors);&lt;/FONT&gt;
       &lt;FONT color=#000000&gt; }&lt;/FONT&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;B&gt;Listing 2.&lt;/B&gt; Code example showing programmatic view generation. Full code can be downloaded &lt;A href="http://code.msdn.microsoft.com/EdmGen2" mce_href="http://code.msdn.microsoft.com/EdmGen2"&gt;here&lt;/A&gt;. 
&lt;H4&gt;Coming Up Next&lt;/H4&gt;
&lt;P&gt;In the final installment of this four-part series, we combine the code we’ve written into a new command-line tool called EdmGen2.exe. This is similar in functionality to EdmGen.exe, but understands how to read &amp;amp; write EDMX files. 
&lt;P&gt;Mike Kaufman&lt;BR&gt;Software Design Engineer&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8658447" 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/EDM/default.aspx">EDM</category></item><item><title>EDM Tools | Options (Part 1 of 4)</title><link>http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-1-of-4.aspx</link><pubDate>Sat, 21 Jun 2008 00:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8627347</guid><dc:creator>dpblogs</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/adonet/comments/8627347.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=8627347</wfw:commentRss><description>&lt;H4&gt;Introduction&lt;/H4&gt;
&lt;P&gt;The Entity Data Model (EDM) Tools team has done a lot of work to enable a productive developer experience using the Microsoft Entity Framework. Model generation, model validation, and code generation are all plugged into the Visual Studio (VS) environment for a seamless user experience. Model generation is accomplished through a Visual Studio wizard, while model validation and code generation are behind-the-scenes operations that users generally need not think about. Consequently, you may not realize that the tooling functionality integrated into Visual Studio is also available from the command-line (via &lt;A href="http://msdn.microsoft.com/en-us/library/bb387165.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb387165.aspx"&gt;EdmGen.exe&lt;/A&gt;), and via programmatic APIs defined in the &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.aspx"&gt;System.Data.Entity.Design&lt;/A&gt; namespace and assembly. Access to this functionality can be very useful. For example, you can hook code-generation and validation into your automated build. Or, you can write your own tools, like MSBuild tasks, to generate code or validate models. 
&lt;P&gt;This is the first in a series of four posts that look at tooling options for the EDM. In this series, we review some of the EDM tooling processes that are integrated into Visual Studio, and discusses alternatives for running these outside of VS - either from the command-line or from your own program. The motivating example we use is building a simple replacement for the .Net Framework tool &lt;A href="http://msdn.microsoft.com/en-us/library/bb387165.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb387165.aspx"&gt;EdmGen.exe&lt;/A&gt;. The approach we follow is to first look at a piece of functionality integrated into the Visual Studio experience. Then, we look at how it is available via the &lt;A href="http://msdn.microsoft.com/en-us/library/bb387165.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb387165.aspx"&gt;EdmGen.exe&lt;/A&gt; tool, and then we’ll look at the public APIs available in the .Net Framework. 
&lt;P&gt;In this first post, we discuss the different file formats between the Visual Studio tools &amp;amp; the Entity Framework APIs in the .Net Framework. In the &lt;A class="" href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-2-of-4.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-2-of-4.aspx"&gt;second part&lt;/A&gt;, we will review how to generate models from a database, and how to generate code from a model. In the &lt;A class="" href="http://blogs.msdn.com/adonet/archive/2008/06/26/edm-tools-options-part-3-of-4.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/06/26/edm-tools-options-part-3-of-4.aspx"&gt;third part&lt;/A&gt;, we look at the validation of models &amp;amp; mappings. The final part in this series will tie all of the previous examples together into a command-line tool that understands how to read and write the EDMX file formats. 
&lt;P&gt;Full source-code for the full command-line tool is available at &lt;A href="http://code.msdn.microsoft.com/EdmGen2" mce_href="http://code.msdn.microsoft.com/EdmGen2"&gt;http://code.msdn.microsoft.com/EdmGen2&lt;/A&gt;. This contains code for all examples in this series. 
&lt;H4&gt;EDMX files vs. CSDL, SSDL and MSL files&lt;/H4&gt;
&lt;P&gt;Before we discuss the tooling tasks outside of VS, we first need to address a slight difference in file formats. In the beginning, there was only an Entity Framework runtime, and the runtime operated on three different files: one for the “conceptual model” (the .csdl file), another for the “storage model” (the .ssdl file), and a third for the “mapping” (the .msl file). Internally, the Data Programmability team refers to a set of these files as “c/m/s files”. The EDM Tools Team made a decision simplify the VS experience by aggregating the c/m/s files into a single .edmx file. The unfortunate state of affairs for V1 is that &lt;A href="http://msdn.microsoft.com/en-us/library/bb387165.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb387165.aspx"&gt;EdmGen.exe&lt;/A&gt; and the Entity Framework APIs that ship in the .Net runtime can’t read EDMX files. 
&lt;H4&gt;Breaking Down an EDMX File &lt;/H4&gt;
&lt;P&gt;The first bit of Code that we we’ll show you is how to extract an EDMX file into the “c/m/s” parts. This is actually quite simple, since the EDMX file embeds the csdl, ssdl &amp;amp; msl. In the code below, we use &lt;A href="http://msdn.microsoft.com/en-us/library/bb308959.aspx#linqoverview_topic7" mce_href="http://msdn.microsoft.com/en-us/library/bb308959.aspx#linqoverview_topic7"&gt;Linq To Xml&lt;/A&gt; to extract the appropriate data from the EDMX, and write out separate files for the csdl, ssdl &amp;amp; msl. To do the inverse (ie, combine c/m/s files into an EDMX), see the full code listing at the &lt;A href="http://code.msdn.microsoft.com/EdmGen2" mce_href="http://code.msdn.microsoft.com/EdmGen2"&gt;MSDN Code Gallery&lt;/A&gt;.&lt;PRE class=code&gt;     &lt;SPAN style="COLOR: blue"&gt;private static void &lt;FONT color=#000000&gt;FromEdmx(&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FileInfo &lt;FONT color=#000000&gt;edmxFile)&lt;/FONT&gt;
     &lt;FONT color=#0000ff&gt;{&lt;/FONT&gt;
            XDocument &lt;FONT color=#000000&gt;xdoc =&lt;/FONT&gt; XDocument&lt;FONT color=#000000&gt;.Load(edmxFile.FullName);&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// select the csdl element, and write it out
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XElement &lt;FONT color=#000000&gt;csdl = GetCsdlFromEdmx(xdoc);&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;string &lt;FONT color=#000000&gt;csdlFileName = GetFileNameWithNewExtension(edmxFile,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;".csdl"&lt;FONT color=#000000&gt;);&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;File&lt;FONT color=#000000&gt;.WriteAllText(csdlFileName, csdl.ToString());&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// select the ssdl element and write it out
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XElement &lt;FONT color=#000000&gt;ssdl = GetSsdlFromEdmx(xdoc);&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;string &lt;FONT color=#000000&gt;ssdlFileName = GetFileNameWithNewExtension(edmxFile,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;".ssdl"&lt;FONT color=#000000&gt;);&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;File&lt;FONT color=#000000&gt;.WriteAllText(ssdlFileName, ssdl.ToString());&lt;/FONT&gt;

            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// select the msl element and write it out
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XElement &lt;FONT color=#000000&gt;msl = GetMslFromEdmx(xdoc);&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;string &lt;FONT color=#000000&gt;mslFileName = GetFileNameWithNewExtension(edmxFile,&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;".msl"&lt;FONT color=#000000&gt;);&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;File&lt;FONT color=#000000&gt;.WriteAllText(mslFileName, msl.ToString());&lt;/FONT&gt;
     &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}

     private static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XElement &lt;FONT color=#000000&gt;GetCsdlFromEdmx(&lt;/FONT&gt;XDocument &lt;FONT color=#000000&gt;xdoc)&lt;/FONT&gt;
     &lt;FONT color=#0000ff&gt;{&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return (from &lt;FONT color=#000000&gt;item&lt;/FONT&gt; in &lt;FONT color=#000000&gt;xdoc.Descendants(&lt;/FONT&gt;
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XName&lt;FONT color=#000000&gt;.Get(&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Schema"&lt;FONT color=#000000&gt;, csdlNamespace))&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;select &lt;FONT color=#000000&gt;item).First();&lt;/FONT&gt;
     }

     private static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XElement &lt;FONT color=#000000&gt;GetSsdlFromEdmx(&lt;/FONT&gt;XDocument &lt;FONT color=#000000&gt;xdoc)&lt;/FONT&gt;
     &lt;FONT color=#0000ff&gt;{&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return (from &lt;FONT color=#000000&gt;item&lt;/FONT&gt; in &lt;FONT color=#000000&gt;xdoc.Descendants(&lt;/FONT&gt;
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XName&lt;FONT color=#000000&gt;.Get(&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Schema"&lt;FONT color=#000000&gt;, ssdlNamespace)) &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;select &lt;FONT color=#000000&gt;item).First();&lt;/FONT&gt;
     }

     private static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XElement &lt;FONT color=#000000&gt;GetMslFromEdmx(&lt;/FONT&gt;XDocument &lt;FONT color=#000000&gt;xdoc)&lt;/FONT&gt;
     &lt;FONT color=#0000ff&gt;{&lt;/FONT&gt;
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;return (from &lt;FONT color=#000000&gt;item&lt;/FONT&gt; in &lt;FONT color=#000000&gt;xdoc.Descendants(&lt;/FONT&gt;
                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XName&lt;FONT color=#000000&gt;.Get(&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Mapping"&lt;FONT color=#000000&gt;, mslNamespace)) &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;select &lt;FONT color=#000000&gt;item).First();&lt;/FONT&gt;
     }&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;B&gt;Listing 1.&lt;/B&gt; Code to extract CSDL, SSDL &amp;amp; MSL sections from an edmx into files. Full code can be &lt;A href="http://code.msdn.microsoft.com/EdmGen2" mce_href="http://code.msdn.microsoft.com/EdmGen2"&gt;downloaded&lt;/A&gt;. 
&lt;H4&gt;Coming Up Next&lt;/H4&gt;
&lt;P&gt;In &lt;A class="" href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-2-of-4.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/06/20/edm-tools-options-part-2-of-4.aspx"&gt;part two&lt;/A&gt; of this four-part series, we will review the command-line &amp;amp; .NET APIs around EDM model and code generation.&lt;/P&gt;
&lt;P&gt;&lt;SPAN lang=EN-US&gt;&lt;FONT face=Calibri size=3&gt;Mike Kaufman&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-US&gt;&lt;FONT face=Calibri size=3&gt;Software Design Engineer, ADO.NET Tools&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8627347" 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/EDM/default.aspx">EDM</category></item><item><title>How to use a T4 template for View Generation</title><link>http://blogs.msdn.com/adonet/archive/2008/06/20/how-to-use-a-t4-template-for-view-generation.aspx</link><pubDate>Fri, 20 Jun 2008 22:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8626631</guid><dc:creator>dpblogs</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/adonet/comments/8626631.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adonet/commentrss.aspx?PostID=8626631</wfw:commentRss><description>&lt;H4&gt;Background&lt;/H4&gt;
&lt;P&gt;To set the stage for this article, do take a look at &lt;A href="http://blogs.msdn.com/adonet/archive/2008/02/04/exploring-the-performance-of-the-ado-net-entity-framework-part-1.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/02/04/exploring-the-performance-of-the-ado-net-entity-framework-part-1.aspx"&gt;Exploring the Performance of the ADO.NET Entity Framework - Part 1&lt;/A&gt; to learn more about pre-generating views and how they can reduce the startup time for applications that consume ADO.NET Entity Data Models. 
&lt;P&gt;A while back, &lt;A href="http://blogs.msdn.com/jkowalski/" mce_href="http://blogs.msdn.com/jkowalski/"&gt;Jaroslaw Kowalski&lt;/A&gt; from our team posted a great reply about using &lt;A href="http://msdn.microsoft.com/en-us/library/bb387165.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb387165.aspx"&gt;EdmGen.exe&lt;/A&gt; to generate views for your ADO.NET Entity Data Model in this &lt;A href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2580051&amp;amp;SiteID=1" mce_href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2580051&amp;amp;SiteID=1"&gt;forum question&lt;/A&gt;. This information is also available on &lt;A href="http://msdn.microsoft.com/en-us/library/bb896240.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb896240.aspx"&gt;MSDN&lt;/A&gt; for reference. 
&lt;P&gt;While using EdmGen.exe is a good approach for certain view generation scenarios, it is somewhat problematic in the following situations when you use it inside Visual Studio: 
&lt;P&gt;1. It does not work with EDMX files (you need to give it the individual CSDL, MSL and SSDL files) 
&lt;P&gt;2. Getting at the individual CSDL, MSL and SSDL files is a challenge when you’ve set “&lt;EM&gt;Metadata Artifact Processing&lt;/EM&gt;” to “&lt;EM&gt;Embed in Output Assembly&lt;/EM&gt;” in the Entity Designer. 
&lt;P&gt;3. Users are forced to fuss with post-build steps in the project 
&lt;P&gt;This article presents an easier and more intuitive approach to generate pre-compiled views with the &lt;A href="http://msdn.microsoft.com/en-us/library/bb126445.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb126445.aspx"&gt;Text Template Transformation Toolkit&lt;/A&gt; (a.k.a. T4 templates) in Visual Studio 2008. If you are not familiar with T4 templates, &lt;A href="http://msdn.microsoft.com/en-gb/vstudio/cc308634.aspx" mce_href="http://msdn.microsoft.com/en-gb/vstudio/cc308634.aspx"&gt;this video&lt;/A&gt; provides a great introduction. 
&lt;H4&gt;T4 template for view generation&lt;/H4&gt;
&lt;H5&gt;Introduction&lt;/H5&gt;
&lt;P&gt;This article is accompanied by two T4 templates: &lt;EM&gt;CSharp.Views.tt&lt;/EM&gt; for use in C# projects and &lt;EM&gt;VisualBasic.Views.tt&lt;/EM&gt; for use in VB projects. Both versions do the same thing: 
&lt;P&gt;1. Figure out which EDMX file to process based on the file name 
&lt;P&gt;2. Extract the individual CSDL, MSL and SSDL from the EDMX file and 
&lt;P&gt;3. Use public APIs in the ADO.NET Entity Framework to generate views. 
&lt;P&gt;To keep things simple, the code in the T4 template follows a simple file naming convention to determine the EDMX file to process. It assumes that &lt;EM&gt;[edmx-file-name].Views.tt&lt;/EM&gt; will process and generate views for the file &lt;EM&gt;[edmx-file-name].edmx&lt;/EM&gt;. The views are generated in the code behind file &lt;EM&gt;[edmx-file-name].Views.cs&lt;/EM&gt; or &lt;EM&gt;[edmx-file-name].Views.vb&lt;/EM&gt; as the case may be. 
&lt;H5&gt;Usage&lt;/H5&gt;
&lt;P&gt;I think this is one of those things that’s best demonstrated by actually using it, so I’ll jump right into it. 
&lt;H6&gt;C# projects&lt;/H6&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Scenario&lt;/U&gt;&lt;/B&gt;: Generate pre-compiled views for an EDMX file in a C# project 
&lt;P&gt;1. Create a new C# Console project 
&lt;P&gt;2. Add a new ADO.NET Entity Data Model to the project via “&lt;EM&gt;Add…New…Item&lt;/EM&gt;” 
&lt;P&gt;3. Go with the default file name of &lt;EM&gt;Model1.edmx&lt;/EM&gt; 
&lt;P&gt;4. Generate a model from a database (say, Northwind) and complete the wizard 
&lt;P&gt;5. Use “&lt;EM&gt;Add…Existing…Item&lt;/EM&gt;” to add the C# version of the T4 template (&lt;EM&gt;CSharp.Views.tt&lt;/EM&gt;) into the project in the same project directory as &lt;EM&gt;Model1.edmx&lt;/EM&gt; 
&lt;P&gt;&lt;EM&gt;6. &lt;/EM&gt;In Solution Explorer, rename the file &lt;EM&gt;CSharp.Views.tt&lt;/EM&gt; to &lt;EM&gt;Model1.Views.tt&lt;/EM&gt;&lt;EM&gt;&lt;/EM&gt; 
&lt;P&gt;7. Click OK to continue if Visual Studio displays the following dialog: 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002_3.jpg" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002_3.jpg"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=133 alt=clip_image002 src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002_thumb.jpg" width=344 border=0 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002_thumb.jpg"&gt;&lt;/A&gt; 
&lt;P&gt;8. In Solution Explorer, right-click &lt;EM&gt;Model1.Views.tt&lt;/EM&gt; and choose "&lt;EM&gt;Run Custom Tool&lt;/EM&gt;" to generate the views 
&lt;P&gt;9. Visual Studio runs the text transformation code in &lt;EM&gt;Model1.Views.tt&lt;/EM&gt; which processes &lt;EM&gt;Model1.edmx&lt;/EM&gt; to produce the generated views in the code behind file &lt;EM&gt;Model1.Views.cs&lt;/EM&gt; 
&lt;P&gt;10. The generated file &lt;EM&gt;Model1.Views.cs&lt;/EM&gt; is compiled into the output assembly when you build the project 
&lt;P&gt;11. If needed, click “&lt;EM&gt;Show All Files&lt;/EM&gt;” in Solution Explorer to see the generated code behind file 
&lt;H6&gt;VB projects&lt;/H6&gt;
&lt;P&gt;&lt;B&gt;&lt;U&gt;Scenario&lt;/U&gt;&lt;/B&gt;: Generate pre-compiled views for an EDMX file in a VB project 
&lt;P&gt;1. Create a new VB Console project 
&lt;P&gt;2. Add a new ADO.NET Entity Data Model to the project via “&lt;EM&gt;Add…New…Item&lt;/EM&gt;” 
&lt;P&gt;3. Go with the default file name of &lt;EM&gt;Model1.edmx&lt;/EM&gt; 
&lt;P&gt;4. Generate a model from a database (say, Northwind) and complete the wizard 
&lt;P&gt;5. Use “&lt;EM&gt;Add…Existing…Item&lt;/EM&gt;” to add the VB version of the T4 template (&lt;EM&gt;VisualBasic.Views.tt&lt;/EM&gt;) into the project in the same project directory as &lt;EM&gt;Model1.edmx&lt;/EM&gt; 
&lt;P&gt;6. In Solution Explorer, rename the file &lt;EM&gt;VisualBasic.Views.tt&lt;/EM&gt; to &lt;EM&gt;Model1.Views.tt&lt;/EM&gt; 
&lt;P&gt;7. Click OK to continue if Visual Studio displays the following dialog: 
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002%5B1%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002%5B1%5D.jpg"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=140 alt=clip_image002[1] src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002%5B1%5D_thumb.jpg" width=363 border=0 mce_src="http://blogs.msdn.com/blogfiles/adonet/WindowsLiveWriter/UsingaT4templateforViewGeneration_AA49/clip_image002%5B1%5D_thumb.jpg"&gt;&lt;/A&gt; 
&lt;P&gt;8. In Solution Explorer, right-click &lt;EM&gt;Model1.Views.tt&lt;/EM&gt; and choose "&lt;EM&gt;Run Custom Tool&lt;/EM&gt;" to generate the views 
&lt;P&gt;9. Visual Studio runs the text transformation code in &lt;EM&gt;Model1.Views.tt&lt;/EM&gt; which processes &lt;EM&gt;Model1.edmx&lt;/EM&gt; to produce the generated views in the code behind file &lt;EM&gt;Model1.Views.vb&lt;/EM&gt; 
&lt;P&gt;10. The generated file &lt;EM&gt;Model1.Views.vb&lt;/EM&gt; is compiled into the output assembly when you build the project 
&lt;P&gt;11. If needed, click “&lt;EM&gt;Show All Files&lt;/EM&gt;” in Solution Explorer to see the generated code behind file 
&lt;H5&gt;Tips&lt;/H5&gt;
&lt;P&gt;1. As and when you make changes to the EDMX file, simply right-click &lt;EM&gt;Model1.Views.tt&lt;/EM&gt; in in Solution Explorer and choose "&lt;EM&gt;Run Custom Tool&lt;/EM&gt;" to generate the views 
&lt;P&gt;2. If you have multiple EDMX files in your project then make as many copies of the.tt file and rename appropriately to pair each with each EDMX file 
&lt;P&gt;3. To generate views for all EDMX files in the solution, click the “&lt;EM&gt;Transform All Templates&lt;/EM&gt;” button in the Solution Explorer toolbar (the rightmost button in the toolbar) 
&lt;P&gt;I hope this article helps get your creative juices flowing for similar scenarios. For example, one could imagine a similar approach to do custom code generation from an EDMX file (shameless plug for a future blog post!) 
&lt;P&gt;Sanjay Nagamangalam&lt;BR&gt;Lead PM – ADO.NET Entity Designer&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8626631" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adonet/attachment/8626631.ashx" length="4864" 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><category domain="http://blogs.msdn.com/adonet/archive/tags/EDM/default.aspx">EDM</category></item></channel></rss>