<?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>Entity Framework Design : Entity Framework</title><link>http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx</link><description>Tags: Entity Framework</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Code Only – Further Enhancements</title><link>http://blogs.msdn.com/efdesign/archive/2009/10/12/code-only-further-enhancements.aspx</link><pubDate>Mon, 12 Oct 2009 17:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9906285</guid><dc:creator>efdesign</dc:creator><slash:comments>26</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9906285.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9906285</wfw:commentRss><description>&lt;P&gt;We’ve come a long way since the &lt;A href="http://blogs.msdn.com/efdesign/archive/2009/08/03/code-only-enhancements.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2009/08/03/code-only-enhancements.aspx"&gt;last post on Code-Only&lt;/A&gt;. So it’s high time for another update.&lt;/P&gt;
&lt;P&gt;We’ve been working really hard on Code-Only revving the design, and spotting missing capabilities and responding to feedback both internal and external etc.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The current plan still holds.&amp;nbsp; Code-Only will not be in .Net 4.0 with the possible exception of the DDL features described in the last post.&amp;nbsp; For that portion, the implementation and requirements are more clear to us, and because making the DDL stuff work requires changes to things already in the .NET framework, and getting provider writers lined up, we are still working hard to get the DDL changes into .NET 4.0.&amp;nbsp; The rest of Code-Only will continue to evolve, and we will ship another preview or two, before getting it rolled into .NET as soon as we can after 4.0 ships. &lt;/P&gt;
&lt;H3&gt;&lt;/H3&gt;
&lt;H3&gt;&lt;/H3&gt;
&lt;H3&gt;API Refactoring&lt;/H3&gt;
&lt;P&gt;As hinted above, we’ve spent a lot of time validating code only against real world scenarios, and thinking about how the customer code hangs together etc. As a results we’ve done some API refactoring.&lt;/P&gt;
&lt;H4&gt;Mappings are now part of Configurations&lt;/H4&gt;
&lt;P&gt;In the last version Mappings were derived from Configurations, which had some strange side-effects on the API. &lt;/P&gt;
&lt;P&gt;We’ve re-arranged things now so that Configurations hold mappings, which are terminated by assignment to a table.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder.Entity&amp;lt;Customer&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .HasKey(c =&amp;gt; c.ID) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapSingleType(c =&amp;gt; new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cid = c.ID, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nme = c.Name &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.custs”);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This maps the Customer entity to the ‘dbo.Custs’ table, the ID property to the cid column, the Name property to the nme column, and registers the ID property as the EntityKey / Primary Key.&lt;/P&gt;
&lt;P&gt;As you can see we’ve also added a helper method called Entity&amp;lt;TEntity&amp;gt;() so that you can fluently create configurations and mappings. You might also have noticed that we have removed RegisterKey and replaced it with HasKey which we feel is more inline with our goal of having an intentional API.&lt;/P&gt;
&lt;H4&gt;TPH mapping syntax no longer violates DRY&lt;/H4&gt;
&lt;P&gt;The previous syntax for specifying a &lt;A href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx"&gt;TPH&lt;/A&gt; mapping forced you to repeat mappings for columns that could easily have been inherited.&lt;/P&gt;
&lt;P&gt;This was unfortunate because we normally encourage TPH because generally it has the best performance characteristics.&lt;/P&gt;
&lt;P&gt;This is where MapHierarchy() and Case() come in. &lt;/P&gt;
&lt;P&gt;Imagine if we want to write these classes using TPH:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public class Person{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual int ID {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual string Firstname {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual string Surname {get;set;} &lt;BR&gt;} &lt;BR&gt;public class Employee: Person &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual Employee Manager {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual List&amp;lt;Employee&amp;gt; Reports {get;set;} &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;You would now do it like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Entity&amp;lt;Person&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .HasKey(p =&amp;gt; p.ID) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapHierarchy() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Case&amp;lt;Person&amp;gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p =&amp;gt; new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.ID, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Firstname,&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Surname, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thisIsADiscriminator = “P” &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Case&amp;lt;Employee&amp;gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e =&amp;gt; new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; manager = e.Manager.Id &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thisIsADiscriminator = “E” &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.People”);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;By using Case&amp;lt;&amp;gt; mappings are re-used for derived type, so there is no need to repeat column mappings for ID, Firstname and Surname. &lt;/P&gt;
&lt;P&gt;Which means the Employee Case statement is only responsible for mapping properties and references declared by the Employee class, and for specifying a new discriminator value. &lt;/P&gt;
&lt;P&gt;The discriminator column and values are there so the Entity Framework can distinguish between rows in the dbo.People table that represent Person objects and those that represent Employee objects.&lt;/P&gt;
&lt;H4&gt;MapSingleType and MapHierarchy&lt;/H4&gt;
&lt;P&gt;Because Mappings are now part of the configuration, there is no need to create them independently and assign them. &lt;/P&gt;
&lt;P&gt;You now simply MapXXX() methods on the EntityConfiguration.&lt;/P&gt;
&lt;P&gt;The available mapping methods are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;MapSingleType(λ) &lt;/LI&gt;
&lt;LI&gt;MapHierarchy(λ) &lt;/LI&gt;
&lt;LI&gt;MapHierarchy().Case&amp;lt;TEntity&amp;gt;(λ).Case&amp;lt;TDerived&amp;gt;(λ). &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;If you know the Entity Frameworks MSL files these correspond to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Type &lt;/LI&gt;
&lt;LI&gt;OfType &lt;/LI&gt;
&lt;LI&gt;OfType with an addition requirement for a type discriminator &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;These mappings can be combined in many interesting ways, but in general this table shows the recommended way to do most common mappings:&lt;/P&gt;
&lt;TABLE border=1 cellSpacing=0 cellPadding=2 width=426 height=544&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=96&gt;&lt;B&gt;Scenario&lt;/B&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=184&gt;&lt;B&gt;Code &lt;BR&gt;&lt;/B&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=268&gt;&lt;B&gt;Notes&lt;/B&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=96&gt;No Inheritance&lt;/TD&gt;
&lt;TD vAlign=top width=184&gt;builder.Entity&amp;lt;A&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapSingleType(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.A”); &lt;BR&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=268&gt;Columns not mapped are not part of the Entity.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=96&gt;TPH&lt;/TD&gt;
&lt;TD vAlign=top width=184&gt;builder.Entity&amp;lt;A&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapHierarchy() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Case&amp;lt;A&amp;gt;(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Case&amp;lt;B&amp;gt;(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Case&amp;lt;C&amp;gt;(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.ABC”); &lt;BR&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=268&gt;Generally each Case expression only maps properties declared by the current type and the discriminator for that type. &lt;BR&gt;&lt;BR&gt;But it is possible to override the mapping for inherited properties if required. &lt;BR&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=96&gt;TPT&lt;/TD&gt;
&lt;TD vAlign=top width=184&gt;builder.Entity&amp;lt;A&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapHierarchy(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.A”); &lt;BR&gt;&lt;BR&gt;builder.Entity&amp;lt;B&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapHierarchy(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.B”); &lt;BR&gt;&lt;BR&gt;builder.Entity&amp;lt;C&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapHierarchy(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.C”); &lt;BR&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=268&gt;Each MapHierarchy expression only maps properties declared by the current type, and properties that make up the entity key.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=96&gt;TPC&lt;/TD&gt;
&lt;TD vAlign=top width=188&gt;builder.Entity&amp;lt;A&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapSingleType(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.A”); &lt;BR&gt;&lt;BR&gt;builder.Entity&amp;lt;B&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapSingleType(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.B”); &lt;BR&gt;&lt;BR&gt;builder.Entity&amp;lt;C&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .MapSingleType(λ) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .ToTable(“dbo.C”); &lt;BR&gt;&lt;/TD&gt;
&lt;TD vAlign=top width=268&gt;Each MapSingleType expression maps all properties, both those declared by the current type and those inherited.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;H3&gt;Foreign Keys&lt;/H3&gt;
&lt;P&gt;In Beta2 of .NET 4.0 we added &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;FK Association Support&lt;/A&gt;, so Code-Only needs a way to link a FK property and an Navigation Property together.&lt;/P&gt;
&lt;P&gt;Given this class:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public class Product{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual int ID {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual string Name {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual Category Category {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual int CategoryID {get;set;} &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;You need to be able to tell code-only that Category.ID and CategoryID should have the same value.&lt;/P&gt;
&lt;P&gt;You do it like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder.Entity&amp;lt;Product&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Relationship(p =&amp;gt; p.Category) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .HasConstraint((p,c) =&amp;gt; p.CategoryID == c.ID);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This says that c.ID (i.e. p.Category.ID) must equal p.CategoryID, which tells code-only that p.CategoryID is an FK property and p.Category is a navigation property backed by this FK property.&lt;/P&gt;
&lt;P&gt;HasConstraint(λ) can also be used in conjunction with Relationship(λ).FromProperty(λ) like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder.Entity&amp;lt;Product&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Relationship(p =&amp;gt; p.Category) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .FromProperty(c =&amp;gt; c.Products) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .HasConstraint((p,c) =&amp;gt; p.CategoryID == c.ID);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verd&gt;Which tells code only that Product.Category and Category.Products are inverses and that Product.CategoryID and Product.Category.ID must be the same, which implies Product.CategoryID is an FK property.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3&gt;Missing Navigation Properties&lt;/H3&gt;
&lt;P&gt;Sometimes you don’t have a navigation property or FK property in the Entity which would naturally hold the FK in the database. For example imagine this scenario:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public class Product{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual int ID {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual string Name {get;set;} &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public class Category{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual int ID {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual string Name {get;set;} &lt;BR&gt;&amp;nbsp;&amp;nbsp; public virtual List&amp;lt;Product&amp;gt; Products {get;set;} &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here there is ‘probably’ a one to many relationship between Categories and Products, and that is probably best modeled using an FK in the products table. &lt;/P&gt;
&lt;P&gt;If you start mapping the Product entity you need a way to map the FK column, but there is no reference (i.e. Product.Category) and no FK property (i.e. Product.CategoryID) to map. &lt;/P&gt;
&lt;P&gt;So we added the ability to create a fake navigation property to help out:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder.Entity&amp;lt;Product&amp;gt;().MapSingleType( &lt;BR&gt;&amp;nbsp;&amp;nbsp; p =&amp;gt; new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pid = p.ID, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nme = p.Name &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cid = EntityMap.Related&amp;lt;Category&amp;gt;(c =&amp;gt; c.Products).ID &lt;BR&gt;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;).ToTable(“dbo.Products”);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here the interesting part is EntityMap.Related, it creates a fake navigation property, just so you can use it in the mapping.&lt;/P&gt;
&lt;P&gt;The method signature looks like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public static TEntity Related&amp;lt;TEntity&amp;gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression&amp;lt;Func&amp;lt;TEntity, object&amp;gt; &lt;BR&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Notice that this function simply returns TEntity, so in the above mapping fragment, we are mapping the ID property of the Category class to the cid column, in the ‘dbo.Products’ table.&lt;/P&gt;
&lt;H3&gt;Complex Types&lt;/H3&gt;
&lt;P&gt;Code-Only’s default behavior is to ignore properties that are not recognized as either a primitive type or an EntityType. So to support Complex Types we need a mechanism to register one, like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;var addressConf = builder.ComplexType&amp;lt;Address&amp;gt;();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This returns a ComplexTypeConfiguration through which you can configure the properties of the ComplexType in the same way you configure the properties of an Entity:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;addressConf.Property(a =&amp;gt; a.Street).HasMaxLength(100); &lt;BR&gt;addressConf.Property(a =&amp;gt; a.Zip).HasMaxLength(10);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Now if an entity is mapped by convention and it has a ComplexType property we will automatically introduce columns for each property of the ComplexType.&lt;/P&gt;
&lt;P&gt;If you want to explicitly map the Entity mapping the ComplexType property is pretty simple too:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder.Entity&amp;lt;Person&amp;gt;().MapSingleType( &lt;BR&gt;&amp;nbsp;&amp;nbsp; p =&amp;gt; new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.ID, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fn = p.Firstname, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sn = p.Surname, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; street = p.Address.Street, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip = p.Address.Zip &lt;BR&gt;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;H3&gt;Registering Entity Sets&lt;/H3&gt;
&lt;P&gt;Some of our early CodeOnly adopters wanted to use Code Only without having an specialized ObjectContext, and in theory with is possible:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder = contextBuilder.Create&amp;lt;ObjectContext&amp;gt;(); &lt;BR&gt;builder.Entity&amp;lt;Person&amp;gt;().HasKey(p =&amp;gt; p.ID);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;But what we found is you have no control over the name of the set generated. In this case we will generate an EntitySet called PersonSet, but what if I the name should be People?&lt;/P&gt;
&lt;P&gt;To address this issues we have added this method:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder.RegisterSet&amp;lt;Person&amp;gt;(“People”);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Not only is this useful for specifying names,&amp;nbsp; it also allows you to intentional specify what EntitySets you need. The alternative would be to encode your intent into calls to Entity&amp;lt;TEntity&amp;gt; and Relationship&amp;lt;TRelated&amp;gt;(..).&lt;/P&gt;
&lt;H3&gt;Association Mapping&lt;/H3&gt;
&lt;P&gt;We also need to add support for mapping associations that are not co-located with the Entity. For example take the relationship between Jobs and Candidates. If a candidate can apply for multiple jobs this is a classic example of a many to many relationship. &lt;/P&gt;
&lt;P&gt;If you want to take control of how this relationship is mapped you need a way to specify the mapping for the relationship, like this:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder &lt;BR&gt;&amp;nbsp; .Entity&amp;lt;Job&amp;gt;() &lt;BR&gt;&amp;nbsp; .Relationship(job =&amp;gt; job.Applicants) &lt;BR&gt;&amp;nbsp; .FromProperty(candidate =&amp;gt; candidate.Applications) &lt;BR&gt;&amp;nbsp; .Map(“dbo.JobApplications”, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (job,candidate) =&amp;gt; new { &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; applicantId = candidate.Id, &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; jobId = job.Id &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; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This does a number of things, first it indicates that Job.Candidates and Candidate.Applications are opposite ends of the same relationship.&lt;/P&gt;
&lt;P&gt;Then the Map() call indicates that the relationship should be stored in the “dbo.JobApplications” join table, with a compound PK made up of the applicantId and jobId columns. &lt;/P&gt;
&lt;P&gt;The applicantId holds the candidate.Id, and the jobId holds the job.Id, and in both cases Code Only will emit an FK constraint to ensure referential integrity.&amp;nbsp; &lt;/P&gt;
&lt;H3&gt;Interesting Column Names&lt;/H3&gt;
&lt;P&gt;The existing mapping syntax that uses anonymous types for the table and column definitions, limits you to column names that are valid CLR identifiers.&lt;/P&gt;
&lt;P&gt;So for example if you need to map to a column with a space in the name you can’t.&lt;/P&gt;
&lt;P&gt;To rectify this we added an alternate mapping syntax:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder.Entity&amp;lt;Product&amp;gt;().MapSingleType( &lt;BR&gt;&amp;nbsp;&amp;nbsp; p =&amp;gt; EntityMap.Row( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityMap.Column(p.ID, “p i d”), &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityMap.Column(p.Name), &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityMap.Column(p.CategoryId, “c i d”) &lt;BR&gt;&amp;nbsp;&amp;nbsp; ) &lt;BR&gt;).ToTable(“dbo.Products”);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This snippet of code, maps the Product entity to the “dbo.Products” table and the ID property to a ‘p i d’ column, the Name property to a Name column and the CategoryId property to the ‘c i d’ column.&lt;/P&gt;
&lt;P&gt;This alternate API has another advantage too: it makes it easier to create mapping expressions programmatically, primarily because you no longer need to create an anonymous type when building the expression. Which is really useful if you want to configure code-only at runtime. &lt;/P&gt;
&lt;H3&gt;Extracting the EDMX&lt;/H3&gt;
&lt;P&gt;We’ve also added the ability to get the EDMX that Code Only is producing internally, either via an XmlWriter or as an XDocument:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;DbConnection connection = // some code to get a connection. &lt;BR&gt;XDocument document = builder.GetEdmx(connection);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;// or using XmlWriter &lt;BR&gt;var swriter = new StringWriter(); &lt;BR&gt;var xwriter = new XmlTextWriter(swriter); &lt;BR&gt;builder.WriteEdmx(connection, xwriter); &lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;This is pretty handy if you want to use Code Only to build your model and mappings but then pull them out so you work with the XML and our designer tooling.&lt;/P&gt;
&lt;H3&gt;Setting the StoreType&lt;/H3&gt;
&lt;P&gt;When producing the Storage Model Code Only asks the current database provider to return an appropriate store type for the CLR type and facets specified.&lt;/P&gt;
&lt;P&gt;But some CLR types and facet combinations can map to multiple possible database types. For example fixed length byte[] can map to both binary and timestamp. So in this situation SqlClient returns binary by default. &lt;/P&gt;
&lt;P&gt;But you might need a timestamp:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Entity&amp;lt;Order&amp;gt;() &lt;BR&gt;&amp;nbsp;&amp;nbsp; .Property(o =&amp;gt; o.Version)&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; .HasStoreType(“timestamp”) &lt;BR&gt;&amp;nbsp;&amp;nbsp; .IsComputed();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This tells Code Only that the Version property of Order (which is a byte[]) is computed in the database, and is actually a ‘timestamp’ column, which is computed in the database after every insert / update.&lt;/P&gt;
&lt;H3&gt;DDL Provider Model&lt;/H3&gt;
&lt;P&gt;In our &lt;A href="http://blogs.msdn.com/efdesign/archive/2009/10/06/extending-the-entity-framework-provider-model-to-support-ddl.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2009/10/06/extending-the-entity-framework-provider-model-to-support-ddl.aspx"&gt;last post&lt;/A&gt; we covered our plans around the DDL provider model, so check that out. &lt;/P&gt;
&lt;H3&gt;Summary&lt;/H3&gt;
&lt;P&gt;As you can see Code Only is now looking much more complete.&lt;/P&gt;
&lt;P&gt;But it isn’t completely finished yet, we are still working on the rough edges, so as always we are very interested to get your feedback. &lt;/P&gt;
&lt;P&gt;In particular are there things you think we should add / rename / simplify?&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 Team, Microsoft. &lt;BR&gt;&lt;B&gt;&lt;I&gt;&lt;BR&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/I&gt;&lt;/B&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;B&gt;&lt;I&gt;this post&lt;/I&gt;&lt;/B&gt;&lt;/A&gt;&lt;B&gt;&lt;I&gt;. &lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9906285" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Providers/default.aspx">Providers</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Mapping/default.aspx">Mapping</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/CodeOnly/default.aspx">CodeOnly</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/What_2700_s+New/default.aspx">What's New</category></item><item><title>Extending the Entity Framework Provider Model to support DDL</title><link>http://blogs.msdn.com/efdesign/archive/2009/10/06/extending-the-entity-framework-provider-model-to-support-ddl.aspx</link><pubDate>Tue, 06 Oct 2009 21:24:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9903877</guid><dc:creator>efdesign</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9903877.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9903877</wfw:commentRss><description>&lt;p&gt;As part of the first previews of &lt;a href="http://blogs.msdn.com/efdesign/archive/2009/08/03/code-only-enhancements.aspx"&gt;Code-Only&lt;/a&gt; we shared some code to create a database:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;// Create a context using code-only      &lt;br /&gt;using (var mycontext = builder.Create(dbConnection))       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // Create the database if it doesn’t already exist       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (!myContext.DatabaseExists())       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; myContext.CreateDatabase();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // Standard EF code goes here.       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;But in the first preview of Code-Only this code only worked against SQL Server. &lt;/p&gt;  &lt;p&gt;The problem is that our public Provider Model (i.e. &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.common.dbproviderservices.aspx"&gt;DbProviderServices&lt;/a&gt;) has no Database Definition Language or DDL features.&lt;/p&gt;  &lt;h5&gt;Provider Model Changes&lt;/h5&gt;  &lt;p&gt;To support DDL features across different databases, we plan to extend DbProviderServices, with DDL specific services.&lt;/p&gt;  &lt;p&gt;These services will be accessed through these public methods:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public string CreateDatabaseScript(      &lt;br /&gt;&amp;#160;&amp;#160; string providerManifestToken,       &lt;br /&gt;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public void CreateDatabase(      &lt;br /&gt;&amp;#160;&amp;#160; DbConnection connection,       &lt;br /&gt;&amp;#160;&amp;#160; int? commandTimeout,       &lt;br /&gt;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public bool DatabaseExists(      &lt;br /&gt;&amp;#160;&amp;#160; DbConnection connection,       &lt;br /&gt;&amp;#160;&amp;#160; int? commandTimeout,       &lt;br /&gt;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public void DeleteDatabase(      &lt;br /&gt;&amp;#160;&amp;#160; DbConnection connection,       &lt;br /&gt;&amp;#160;&amp;#160; int? commandTimeout,       &lt;br /&gt;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Now internally those methods will call through to the following ‘protected virtual’ methods which will do the actual work: &lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;protected virtual string DbCreateDatabaseScript(      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string providerManifestToken,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;protected virtual void DbCreateDatabase(      &lt;br /&gt;&amp;#160;&amp;#160; DbConnection connection,       &lt;br /&gt;&amp;#160;&amp;#160; int? commandTimeout,       &lt;br /&gt;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;protected virtual bool DbDatabaseExists(      &lt;br /&gt;&amp;#160;&amp;#160; DbConnection connection,       &lt;br /&gt;&amp;#160;&amp;#160; int? commandTimeout,       &lt;br /&gt;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;protected virtual void DbDeleteDatabase(      &lt;br /&gt;&amp;#160;&amp;#160; DbConnection connection,       &lt;br /&gt;&amp;#160;&amp;#160; int? commandTimeout,       &lt;br /&gt;&amp;#160;&amp;#160; StoreItemCollection storeItemCollection);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;And the base implementations of these methods in DbProviderServices will simply throw ProviderIncompatibleExceptions. &lt;/p&gt;  &lt;p&gt;Which means the provider writers job will be to override these ‘protected virtual’ methods with an implementation that makes sense for their backend database.&lt;/p&gt;  &lt;p&gt;The key is to understand that the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.storeitemcollection.aspx"&gt;StoreItemCollection&lt;/a&gt; (aka the SSDL or StorageModel part of the EDMX) represents the intended shape of the database. &lt;/p&gt;  &lt;p&gt;This means the provider writer will need to iterate over the EntitySets (tables) and the corresponding EntityTypes (table structures) in the StoreItemCollection and create / drop / script the database and tables as required.&lt;/p&gt;  &lt;p&gt;Provider writers will be expected to override these functions so that:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;DbCreateDatabaseScript:&lt;/strong&gt; creates a native text command to create the tables and foreign key constraints defined in the StoreItemCollection. I.e. for SqlClient this would be the contents of a .sql DDL file. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DbCreateDatabase:&lt;/strong&gt; is similar to DbCreateDatabaseScript except it should actually goes ahead and create the database, tables and foreign key constraints. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DbDatabaseExists:&lt;/strong&gt; checks to see if the database exists. The SqlClient provider will simply check that the database itself exists, but custom provider writers could get more fancy and check to see if every table / foreign key constraint is found too. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DbDeleteDatabase:&lt;/strong&gt; should go ahead and delete the database, or if the database server has a single database model (like Oracle) the provider writer should delete just the tables defined in the StoreItemCollection. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Simplifying Wrapping Providers&lt;/h5&gt;  &lt;p&gt;We are also planning something to simplify writing Wrapping Providers. A wrapping provider is just a provider that wraps an existing provider (i.e. SqlClient) and adds additional services (i.e. Auditing, Logging, Caching etc). &lt;/p&gt;  &lt;p&gt;Jarek has some &lt;a href="http://blogs.msdn.com/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx"&gt;some sample wrapping providers&lt;/a&gt; if you are interested.&lt;/p&gt;  &lt;p&gt;Today writing a wrapping provider is a little tricky, in fact one ‘protected’ method is impossible to wrap without reflection. So to help we plan to add one public wrapper method:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public DbCommandDefinition CreateCommandDefinition(      &lt;br /&gt;&amp;#160;&amp;#160; DbProviderManifest providerManifest,       &lt;br /&gt;&amp;#160;&amp;#160; DbCommandTree commandTree);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;One of the reasons we plan on doing this, is we think people might take a ‘basic’ provider that has no DDL support and wrap it to add DDL support.&lt;/p&gt;  &lt;h5&gt;End User API&lt;/h5&gt;  &lt;p&gt;Now so far we’ve been looking at the planned extensions to Provider Services, but Provider Services is a very low level API that few developers will ever program against.&lt;/p&gt;  &lt;p&gt;Most people will work directly against the ObjectContext, to which we plan to add these methods:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public void CreateDatabase()&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public void DeleteDatabase();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public bool DatabaseExists();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;public String CreateDatabaseScript();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This little snippet shows how easy it will be to script, create, check and delete a database:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;MyContext ctx = new MyContext();      &lt;br /&gt;String sql = ctx.CreateDatabaseScript();       &lt;br /&gt;ctx.CreateDatabase();       &lt;br /&gt;Assert.True(ctx.DatabaseExists());       &lt;br /&gt;ctx.DeleteDatabase();       &lt;br /&gt;Assert.False(ctx.DatabaseExists());&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;As you it could hardly be easier to use.&lt;/p&gt;  &lt;h5&gt;Summary:&lt;/h5&gt;  &lt;p&gt;While Code-Only provides the catalyst to add DDL support to the Entity Framework’s Provider model, this feature is about &lt;a href="http://blogs.msdn.com/alexj/archive/2009/08/12/tip-32-how-to-create-a-database-from-ssdl-ef-4-only.aspx"&gt;more than just Code-Only&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;In fact we think this feature will add significantly to the usability of the Entity Framework. &lt;/p&gt;  &lt;p&gt;But as always we are keen to hear what you think.&lt;/p&gt;  &lt;p&gt;&lt;a 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 Team, Microsoft.     &lt;br /&gt;&lt;b&gt;&lt;i&gt;       &lt;br /&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/i&gt;&lt;/b&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;b&gt;&lt;i&gt;this post&lt;/i&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;i&gt;. &lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9903877" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Providers/default.aspx">Providers</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/CodeOnly/default.aspx">CodeOnly</category></item><item><title>LINQ to SQL to Entity Framework conversion template</title><link>http://blogs.msdn.com/efdesign/archive/2009/08/13/linq-to-sql-to-entity-framework-conversion-template.aspx</link><pubDate>Fri, 14 Aug 2009 00:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9868818</guid><dc:creator>efdesign</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9868818.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9868818</wfw:commentRss><description>&lt;P&gt;Many customers have asked us how to port a LINQ to SQL application to the Entity Framework. In order to make this process easier, we have developed a metadata conversion template. &lt;/P&gt;
&lt;P&gt;This template converts LINQ to SQL metadata (.dbml) to metadata compatible with Entity Framework (.edmx). While not a complete solution to the conversion problem, it is a useful first step. The template available for download is still in the development stage, and any feedback you have on the user experience, additional features, or any other aspect of the conversion would be greatly appreciated. &lt;/P&gt;
&lt;P&gt;The T4 template is intended to convert simple valid .dbml files to .edmx files. All of the basic elements of the .dbml file are mapped to their .edmx counterparts. For instance, Tables are mapped to EntitySets and Types are mapped to EntityTypes. Additionally, stored procedures (including customized insert, update and delete stored procedures) and associations are also converted. &lt;/P&gt;
&lt;H4&gt;Downloading the Metadata Conversion Template&lt;/H4&gt;
&lt;P&gt;Included in the zip file is a .vsix installer for the T4 Conversion Template. Also included is detailed documentation for the template. VS 2010 Beta 1 is required.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/efdesign/attachment/9868818.ashx" mce_href="http://blogs.msdn.com/efdesign/attachment/9868818.ashx"&gt;Download the Template&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;&lt;/H4&gt;
&lt;H4&gt;Walkthroughs&lt;/H4&gt;
&lt;P&gt;Two walkthroughs have been written to help guide users through the conversion process. The walkthroughs both take the form of unit tests which can be run against the existing LINQ to SQL metadata and the Entity Framework metadata produced by the conversion template. Each walkthrough contains detailed instructions on how to convert the existing LINQ to SQL project to Entity Framework using the Conversion Template. The first is the Widget Factory walkthrough, which shows a basic conversion. The second (CustomCUD) shows how to convert a LINQ to SQL project which uses custom insert, update and delete stored procedures. The walkthroughs are available individually. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/efdesign/pages/widget-factory-walkthrough-for-the-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx" mce_href="http://blogs.msdn.com/efdesign/pages/widget-factory-walkthrough-for-the-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx"&gt;Widget Factory Walkthrough&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/efdesign/pages/custom-cud-walkthrough-for-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx" mce_href="http://blogs.msdn.com/efdesign/pages/custom-cud-walkthrough-for-linq-to-sql-to-entity-framework-metadata-conversion-template.aspx"&gt;Custom CUD Walkthrough&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;&lt;/H4&gt;
&lt;H4&gt;Caveats and Known Issues&lt;/H4&gt;
&lt;P&gt;Because the Conversion Template is still under development, there are a number of open issues and unimplemented features. A more comprehensive list can be found in the documentation included with the template installer. &lt;/P&gt;
&lt;P&gt;· Inheritance: Inheritance has not been fully implemented. While the template may work in some basic cases, this aspect of the conversion remains an open issue.&lt;/P&gt;
&lt;P&gt;· Independent Associations: Foreign-key associations will not be available until .NET 4.0 Beta 2, so the current version of the template will only work with the "UseIndependentAssociations" flag set to true.&lt;/P&gt;
&lt;P&gt;· Property Attributes: not all of the property attributes (such as "Unicode" and "FixedLength") are converted because these are not explicitly present in the .dbml file.&lt;/P&gt;
&lt;H4&gt;Feedback&lt;/H4&gt;
&lt;P&gt;We are interested to hear any comments you have about known issues, additional feature requests, suggestions for additional walkthroughs or any other aspect of the conversion process.&lt;/P&gt;
&lt;P&gt;Thanks, &lt;BR&gt;&lt;STRONG&gt;Christina Ilvento &lt;BR&gt;&lt;/STRONG&gt;Developer, &lt;BR&gt;Entity Framework Team&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9868818" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/efdesign/attachment/9868818.ashx" length="45365" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Linq+to+Sql/default.aspx">Linq to Sql</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Templates/default.aspx">Templates</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Migration/default.aspx">Migration</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category></item><item><title>Code Only Enhancements</title><link>http://blogs.msdn.com/efdesign/archive/2009/08/03/code-only-enhancements.aspx</link><pubDate>Tue, 04 Aug 2009 01:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9856565</guid><dc:creator>efdesign</dc:creator><slash:comments>30</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9856565.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9856565</wfw:commentRss><description>&lt;p&gt;We've been working hard on Code Only since the &lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-entity-framework.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-entity-framework.aspx"&gt;first preview&lt;/a&gt;.&lt;/p&gt;In the next release you will be able to specify: 
&lt;ol&gt;
&lt;li&gt;Navigation Property Inverses. &lt;/li&gt;
&lt;li&gt;Property Facets, like &lt;font face="Courier New"&gt;Nullability&lt;/font&gt;, &lt;font face="Courier New"&gt;MaxLength&lt;/font&gt;, &lt;font face="Courier New"&gt;Precision&lt;/font&gt; etc. &lt;/li&gt;
&lt;li&gt;Property to Column mappings &lt;/li&gt;
&lt;li&gt;Type to Table(s) mappings &lt;/li&gt;
&lt;li&gt;Inheritance strategy &lt;/li&gt;
&lt;li&gt;Encapsulate configuration &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;The rest of this post will drill into each of these features in turn.&lt;/p&gt;
&lt;h3&gt;Registering NavigationProperty inverses:&lt;/h3&gt;
&lt;p&gt;You can now Register Inverses, i.e. link one navigation property to another, like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.RegisterInverse( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Customer c) =&amp;gt; c.Orders, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Order o) =&amp;gt; o.Customer) &lt;br&gt;);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This code indicates that &lt;font face="Courier New"&gt;Customer.Orders&lt;/font&gt; is the other end of the &lt;font face="Courier New"&gt;Order.Customer&lt;/font&gt; relationship. Adding &lt;font face="Courier New"&gt;order1&lt;/font&gt; to the &lt;font face="Courier New"&gt;customer1.Orders&lt;/font&gt; collection, has the same effect as setting the &lt;font face="Courier New"&gt;order1.Customer&lt;/font&gt; to &lt;font face="Courier New"&gt;customer1&lt;/font&gt;.&lt;/p&gt;
&lt;h3&gt;Specifying Property Facets:&lt;/h3&gt;
&lt;p&gt;You can also specify property facets, i.e. things like Nullability, MaxLength, Precision etc, like this:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;var customerConfig = new EntityConfiguration&amp;lt;Customer&amp;gt;(); &lt;br&gt;// We can infer that the ID is the Primary Key, &lt;br&gt;// but not that it is generated in the database on insert. &lt;br&gt;customerConfig.ForProperty(c =&amp;gt; c.ID) &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; .Identity(); &lt;br&gt;customerConfig.ForProperty(c =&amp;gt; c.Name) &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; .MaxLength(100) &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; .NonUnicode(); &lt;br&gt;customerConfig.ForProperty(c =&amp;gt; c.Website) &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; .MaxLength(200) &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; .Nullable()&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Configure(customerConfig);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This configures the &lt;font face="Courier New"&gt;Customer&lt;/font&gt; type so that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;font face="Courier New"&gt;ID&lt;/font&gt; property is an &lt;font face="Courier New"&gt;Identity&lt;/font&gt; column, i.e. the value is computed by the database when we do an insert. &lt;/li&gt;
&lt;li&gt;The &lt;font face="Courier New"&gt;Name&lt;/font&gt; property has a &lt;font face="Courier New"&gt;MaxLength&lt;/font&gt; of &lt;font face="Courier New"&gt;100&lt;/font&gt; characters and is &lt;font face="Courier New"&gt;NonUnicode&lt;/font&gt; i.e. in SqlServer &lt;font face="Courier New"&gt;VARCHAR&lt;/font&gt; rather than &lt;font face="Courier New"&gt;NVARCHAR&lt;/font&gt;. &lt;/li&gt;
&lt;li&gt;The &lt;font face="Courier New"&gt;Website&lt;/font&gt; property has a &lt;font face="Courier New"&gt;MaxLength&lt;/font&gt; of &lt;font face="Courier New"&gt;200&lt;/font&gt; characters and is &lt;font face="Courier New"&gt;Nullable&lt;/font&gt;. &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;These facets target the Conceptual Model (i.e. CSDL), and from there flow to the database too (i.e. SSDL).&lt;/p&gt;
&lt;h4&gt;Encapsulating Facet Configuration&lt;/h4&gt;
&lt;p&gt;You can create a class to encapsulate all this configuration by deriving from &lt;font face="Courier New"&gt;EntityConfiguration&amp;lt;T&amp;gt;&lt;/font&gt;.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;public class CustomerConfig: EntityConfiguration&amp;lt;Customer&amp;gt; &lt;br&gt;{ &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public CustomerConfig(){ &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ForProperty(c =&amp;gt; c.ID) &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;&amp;nbsp;&amp;nbsp; .Identity(); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ForProperty(c =&amp;gt; c.Name) &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;&amp;nbsp;&amp;nbsp; .MaxLength(100) &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;&amp;nbsp;&amp;nbsp; .NonUnicode(); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ForProperty(c =&amp;gt; c.Website) &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;&amp;nbsp;&amp;nbsp; .MaxLenght(200) &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;&amp;nbsp;&amp;nbsp; .Nullable(); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;We recommend creating classes like this instead of configuring an &lt;font face="Courier New"&gt;EntityConfiguration&amp;lt;&amp;gt;&lt;/font&gt; because of the encapsulation benefits.&lt;/p&gt;
&lt;h4&gt;Specifying the Tablename&lt;/h4&gt;
&lt;p&gt;When you use &lt;font face="Courier New"&gt;Configure&amp;lt;T&amp;gt;(..)&lt;/font&gt; the EF infers a default mapping, inheritance strategy (&lt;a href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx"&gt;TPH&lt;/a&gt;) and table name(s) for you.&lt;/p&gt;
&lt;p&gt;But if you want to specify the table name you can do this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;var customerConfig = new EntityConfiguration&amp;lt;Customer&amp;gt;(); &lt;br&gt;// configure the facets, as per the above example &lt;br&gt;...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;// register configuration with a particular tablename &lt;br&gt;builder.Tables[“dbo.Custs”] = customerConfig;&lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;Specifying Mappings:&lt;/h3&gt;
&lt;p&gt;If you need more control over the mappings (for example to map to an existing database or use corporate naming policies) then you can specify mappings like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;EntityMap&amp;lt;Customer&amp;gt; customerMap =&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.OfType&amp;lt;Customer&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c =&amp;gt; new { &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; cid = c.ID, &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; c.Name, &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; csite = c.Website &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/font&gt; &lt;/p&gt;
&lt;h4&gt;Interpreting a Mapping&lt;/h4&gt;
&lt;p&gt;This mapping states that the &lt;font face="Courier New"&gt;ID&lt;/font&gt; property is mapped to the ‘&lt;font face="Courier New"&gt;cid&lt;/font&gt;’ column, the &lt;font face="Courier New"&gt;Name&lt;/font&gt; property is stored in the ‘&lt;font face="Courier New"&gt;Name&lt;/font&gt;’ column and the Website property is mapped to the ‘&lt;font face="Courier New"&gt;csite&lt;/font&gt;’ column.&lt;/p&gt;
&lt;p&gt;Properties not referenced are not persisted (just like properties in a partial class when using the default code generation of EF)&lt;/p&gt;
&lt;h4&gt;LINQ Comprehension Syntax&lt;/h4&gt;
&lt;p&gt;You can even specify exactly the same thing using a LINQ comprehension syntax too:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;EntityMap&amp;lt;Customer&amp;gt; customerMap = &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from c in Map.OfType&amp;lt;Customer&amp;gt;()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select new { &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; cid = c.ID, &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; c.Name, &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; csite = c.Website &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/font&gt;&lt;/p&gt;
&lt;h4&gt;Specifying Facets with Mapping&lt;/h4&gt;
&lt;p&gt;Once you’ve configured the mapping you can also specify facets on the map like this: &lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;customerMap.ForProperty(c =&amp;gt; c.ID) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Identity(); &lt;br&gt;customerMap.ForProperty(c =&amp;gt; c.Name) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .MaxLength(100) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .NonUnicode(); &lt;br&gt;customerMap.ForProperty(c =&amp;gt; c.Website) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .MaxLenght(200) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Nullable();&lt;/font&gt;&lt;/p&gt;
&lt;h4&gt;Specifying the table&lt;/h4&gt;
&lt;p&gt;The final step is to assign the map to a table.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.Custs”] = customerMap;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Now we’ve specified a custom table, mapping and custom facets for our &lt;font face="Courier New"&gt;Customer&lt;/font&gt; class.&lt;/p&gt;
&lt;h3&gt;Specifying Inheritance:&lt;/h3&gt;
&lt;p&gt;The default inheritance strategy used by CodeOnly is Table Per Hierarchy (or &lt;a href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx"&gt;TPH&lt;/a&gt;). &lt;/p&gt;
&lt;p&gt;If however you need a different strategy you need to dive in and configure the mappings.&lt;/p&gt;
&lt;p&gt;Imagine if you have three classes you need to map: &lt;font face="Courier New"&gt;Vehicle&lt;/font&gt; , &lt;font face="Courier New"&gt;Car&lt;/font&gt; and &lt;font face="Courier New"&gt;Boat&lt;/font&gt; where both &lt;font face="Courier New"&gt;Car&lt;/font&gt; and &lt;font face="Courier New"&gt;Boat&lt;/font&gt; are derived from&lt;font face="Courier New"&gt; &lt;/font&gt;&lt;font face="Courier New"&gt;Vehicle&lt;/font&gt; which is &lt;font face="Courier New"&gt;abstract.&lt;/font&gt;&lt;/p&gt;
&lt;h6&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CodeOnlyEnhancements_D54B/clip_image001_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CodeOnlyEnhancements_D54B/clip_image001_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CodeOnlyEnhancements_D54B/clip_image001_thumb.jpg" style="border-width: 0px; display: inline;" title="clip_image001" alt="clip_image001" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CodeOnlyEnhancements_D54B/clip_image001_thumb.jpg" width="445" border="0" height="423"&gt;&lt;/a&gt;&lt;/h6&gt;
&lt;h4&gt;Table Per Hierarchy (TPH)&lt;/h4&gt;
&lt;p&gt;If you want to map this using &lt;a href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx"&gt;TPH&lt;/a&gt;, you could do it like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;var vehicleMap =&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.OfTypeOnly&amp;lt;Vehicle&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v =&amp;gt; new { &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; vid = v.ID, &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; v.Name, &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; vdesc = v.Description &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; v.MaxPassengers, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ).Union(Map.OfTypeOnly&amp;lt;Car&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c =&amp;gt; new {&amp;nbsp;&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vid = c.ID,&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; c.Name, &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; vdesc = c.Description&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; c.MaxPassengers,&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; trans = c.Transmission, &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; tspd = c.Topspeed, &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; ccty = c.EngineCapacity, &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; ncyld = c.NoCylinder, &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; discriminator = “CAR” &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ).Union(Map.OfTypeOnly&amp;lt;Boat&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b =&amp;gt; new {&amp;nbsp;&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vid = b.ID,&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; b.Name, &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; vdesc = b.Description&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; b.MaxPassengers,&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; lng = b.Length, &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; b.HasSail, &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; b.HasEngine &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; discriminator = “BOAT” &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.vehicles”] = vehicleMap;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;In a TPH mapping:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;OfTypeOnly() is used to create mapping fragments.&lt;/li&gt;
&lt;li&gt;Mapping fragments are&amp;nbsp;then unioned so they can be assigned to one table (TPH uses a single table for the whole hierarchy). &lt;/li&gt;
&lt;li&gt;A discriminator column is required for each non-abstract type. The discriminator column can have any name and must have a different constant value (i.e. “CAR”) for each non abstract type in the hierarchy. &lt;/li&gt;
&lt;li&gt;When mapping a derived type you&amp;nbsp;must&amp;nbsp;re-map all properties mapped in the base-type(s). &lt;/li&gt;&lt;/ol&gt;
&lt;h4&gt;Table Per Type (TPT)&lt;/h4&gt;
&lt;p&gt;If you want to map the same hierarchy using Table Per Type or &lt;a href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx"&gt;TPT&lt;/a&gt;, this is how you do it:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Table[“dbo.Vehicles”]=&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.OfType&amp;lt;Vehicle&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v =&amp;gt; new { &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; vid = v.ID, &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; v.Name, &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; vdesc = v.Description &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; v.MaxPassengers, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.Cars”] =&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.OfType&amp;lt;Car&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c =&amp;gt; new { &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; cid = c.ID, &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; trans = c.Transmission, &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; tspd = c.Topspeed, &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; ccty = c.EngineCapacity, &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; ncyld = c.NoCylinders, &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; );&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.Boats”] =&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.OfType&amp;lt;Boat&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b =&amp;gt; new { &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; bid = b.ID, &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; lng = b.Length, &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; b.HasSail, &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; b.HasEngine &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;In a TPT mapping:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;OfType&amp;lt;&amp;gt;() is used in each mapping 'fragment'&lt;/li&gt;
&lt;li&gt;Each mapping 'fragment' is assigned to a different table.&lt;/li&gt;
&lt;li&gt;Each mapping 'fragment' only maps properties declared on the current type, except… &lt;/li&gt;
&lt;li&gt;Key properties must be mapped in every fragment (this allows the tables participating in the type to be joined). &lt;/li&gt;
&lt;li&gt;There are no discriminators &lt;/li&gt;&lt;/ol&gt;
&lt;h4&gt;Table Per Class (TPC)&lt;/h4&gt;
&lt;p&gt;You can also map this hierarchy using &lt;a href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx"&gt;TPC&lt;/a&gt; like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.Cars”] =&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.OfTypeOnly&amp;lt;Car&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c =&amp;gt; new { &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; cid = c.ID, &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; c.Name, &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; vdesc = c.Description &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; c.MaxPassengers, &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; trans = c.Transmission, &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; tspd = c.Topspeed, &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; ccty = c.EngineCapacity, &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; ncyld = c.NoCylinders, &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; );&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.Boats”] =&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map.OfTypeOnly&amp;lt;Boat&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b =&amp;gt; new { &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; bid = b.ID, &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; b.Name, &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; description = b.Description &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; b.MaxPassengers, &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; lng = b.Length, &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; b.HasSail, &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; b.HasEngine &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;In a TPC Mapping:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Like TPH we use &lt;font face="Courier New"&gt;OfTypeOnly(..)&lt;/font&gt; &lt;/li&gt;
&lt;li&gt;But unlike TPH each non-abstract type has a its own table. (So there is no table for Vehicles because it is abstract). &lt;/li&gt;
&lt;li&gt;Each mapping fragment re-maps every, non-transient, property. &lt;/li&gt;
&lt;li&gt;There is no mapping for any abstract classes in the hierarchy. &lt;/li&gt;
&lt;li&gt;There are no discriminators&lt;/li&gt;&lt;/ol&gt;
&lt;h3&gt;Default Foreign Key Locations:&lt;/h3&gt;
&lt;p&gt;If we see a reference (i.e. &lt;font face="Courier New"&gt;Order.Customer&lt;/font&gt;) we assume the multiplicity is &lt;font face="Courier New"&gt;0..1&lt;/font&gt;. Meaning the the Foreign Key or FK is nullable.&lt;/p&gt;
&lt;p&gt;If we see a collection (i.e. &lt;font face="Courier New"&gt;Customer.Orders&lt;/font&gt;) we assume the multiplicity is &lt;font face="Courier New"&gt;many&lt;/font&gt;. &lt;/p&gt;
&lt;p&gt;Then when you Register Inverses, we know the multiplicity of both ends of the relationships i.e. in the above example we know that there are &lt;font face="Courier New"&gt;0..1 Customers&lt;/font&gt; for an &lt;font face="Courier New"&gt;Order&lt;/font&gt; and &lt;font face="Courier New"&gt;many Orders&lt;/font&gt; for a &lt;font face="Courier New"&gt;Customer&lt;/font&gt;.&lt;/p&gt;
&lt;p&gt;So by convention there are 3 main types of relationships, we need to infer the FK location for:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;0..1 to many&lt;/b&gt; –&amp;gt; by convention we put the FK on the many end. So in the &lt;font face="Courier New"&gt;Customer.Orders&lt;/font&gt; example the FK is put in the &lt;font face="Courier New"&gt;Orders&lt;/font&gt; table.&amp;nbsp; &lt;br&gt;&lt;br&gt;&lt;b&gt;many to many&lt;/b&gt; –&amp;gt; there is no option but to introduce a join table &lt;br&gt;&lt;b&gt;&lt;br&gt;0..1 to 0..1&lt;/b&gt; –&amp;gt; You can configure where the FK lives, but in the absence of configuration we will introduce a join table.&lt;/p&gt;
&lt;p&gt;Sometimes however a reference is not &lt;font face="Courier New"&gt;0..1&lt;/font&gt; it is &lt;font face="Courier New"&gt;1&lt;/font&gt;, i.e. the FK, wherever it might be, may not be &lt;font face="Courier New"&gt;nullable.&lt;/font&gt; &lt;/p&gt;
&lt;p&gt;This is how you specify that the FK is non-nullable:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;var orderConfig = builder.Configure&amp;lt;Order&amp;gt;(); &lt;br&gt;orderConfig.RegisterInverse(o =&amp;gt; o.Customer, c =&amp;gt; c.Orders); &lt;br&gt;orderConfig.ForProperty(o =&amp;gt; o.Customer).NonNullable();&lt;/font&gt; &lt;br&gt;&lt;br&gt;This tells us that there is exactly &lt;font face="Courier New"&gt;1&lt;/font&gt; &lt;font face="Courier New"&gt;Customer&lt;/font&gt; per &lt;font face="Courier New"&gt;Order&lt;/font&gt; and &lt;font face="Courier New"&gt;many Orders&lt;/font&gt; for a &lt;font face="Courier New"&gt;Customer&lt;/font&gt;. &lt;/p&gt;
&lt;p&gt;The ability to tell us that a reference is &lt;font face="Courier New"&gt;NonNullable&lt;/font&gt; introduces several new multiplicity combinations, for which we need conventions too:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;1 to many&lt;/b&gt; –&amp;gt; by convention we put the FK on the many end, and make it non-nullable in the database.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;0..1 to 1&lt;/b&gt; –&amp;gt; by convention we put the FK on the 1 end, and make it non-nullable.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;1 to 1&lt;/b&gt; –&amp;gt; like 0..1 to 0..1 we can’t decide where to put the FK so by convention we introduce a join table.&lt;/p&gt;
&lt;h3&gt;Specifying FK Mappings:&lt;/h3&gt;
&lt;p&gt;So far we’ve created mappings for the properties of entities.&lt;/p&gt;
&lt;p&gt;What about Navigation Properties and FKs? &lt;/p&gt;
&lt;p&gt;All types of relationships (except many to many) can be modeled without a join table in the database. So we allow you to map FKs as part of an &lt;font face="Courier New"&gt;EntityMap&lt;/font&gt; like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;EntityMap&amp;lt;Customer&amp;gt; customerMap = &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from c in Map.OfType&amp;lt;Customer&amp;gt;()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select new { &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; cid = c.ID, &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; c.Name, &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; csite = c.Website, &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; salesPersonFK = c.SalesPerson.ID &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;customerMap.RegisterInverse(c =&amp;gt; c.SalesPerson, s =&amp;gt; c.Clients); &lt;br&gt;builder.Tables[“dbo.Custs”] = customerMap;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This specifies that the &lt;font face="Courier New"&gt;Customer.SalesPerson&lt;/font&gt; navigation property, and it’s inverse &lt;font face="Courier New"&gt;SalesPerson.Customers&lt;/font&gt;, are stored in the &lt;font face="Courier New"&gt;salesPersonFK&lt;/font&gt; column in the&lt;font face="Courier New"&gt; dbo.Custs&lt;/font&gt; table. Because the fragment maps the &lt;font face="Courier New"&gt;salesPersonFK&lt;/font&gt; column to the &lt;font face="Courier New"&gt;c.SalesPerson.ID&lt;/font&gt;, where &lt;font face="Courier New"&gt;SalesPerson.ID&lt;/font&gt; is the Primary Key (or part of the PrimaryKey) of the related &lt;font face="Courier New"&gt;SalesPerson&lt;/font&gt; entity, and of course FK’s point to PK’s.&lt;/p&gt;
&lt;h3&gt;Specifying Join Table Mappings:&lt;/h3&gt;
&lt;p&gt;In the case of many to many relationships you must have a join table, so absent mapping information we produce a join table by convention. &lt;/p&gt;
&lt;p&gt;If however you need more control you can do this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;var blogPostsMap = new AssociationMap&amp;lt;Blog, Post&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b =&amp;gt; b.Posts &lt;br&gt;).Map( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (b, p) =&amp;gt; new {BlogId = b.ID, PostId = p.ID} &lt;br&gt;);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.BlogPosts”] = blogPostsMap;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This says the many to many relationships between &lt;font face="Courier New"&gt;Blog&lt;/font&gt; and &lt;font face="Courier New"&gt;Post&lt;/font&gt; is stored in the ‘&lt;font face="Courier New"&gt;dbo.BlogPosts&lt;/font&gt;’ table which has two columns: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;‘&lt;font face="Courier New"&gt;BlogId&lt;/font&gt;’ which is also an FK pointing to the column to which the &lt;font face="Courier New"&gt;ID&lt;/font&gt; property of &lt;font face="Courier New"&gt;Blog&lt;/font&gt; is mapped. &lt;/li&gt;
&lt;li&gt;‘&lt;font face="Courier New"&gt;PostId&lt;/font&gt;’ which is also an FK pointing to the column to which the &lt;font face="Courier New"&gt;ID&lt;/font&gt; property of &lt;font face="Courier New"&gt;Post&lt;/font&gt; is mapped. &lt;/li&gt;&lt;/ul&gt;
&lt;h3&gt;Entity Splitting:&lt;/h3&gt;
&lt;p&gt;Code Only can even support more advanced mapping strategies like entity splitting:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.Customer”] = Map.OfType&amp;lt;Customer&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp; c =&amp;gt; new { &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cid = c.ID, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.Name, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; active = c.IsActive &lt;br&gt;&amp;nbsp;&amp;nbsp; } &lt;br&gt;);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.CustomerDetails”] = Map.OfType&amp;lt;Customer&amp;gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c =&amp;gt; new { &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cid = c.ID, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.Size, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.Industry &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This says that the &lt;font face="Courier New"&gt;Customer&lt;/font&gt; entity is split across the &lt;font face="Courier New"&gt;dbo.Customer&lt;/font&gt; and &lt;font face="Courier New"&gt;dbo.CustomerDetails&lt;/font&gt; tables.&lt;/p&gt;
&lt;h3&gt;Encapsulating all the Configuration:&lt;/h3&gt;
&lt;p&gt;You can also write a class that derives from &lt;font face="Courier New"&gt;EntityMap&amp;lt;T&amp;gt;&lt;/font&gt;, to hold all the mapping, facets etc. For example here a class that holds the configuration for &lt;font face="Courier New"&gt;Product&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;public class ProductMap: EntityMap&amp;lt;Product&amp;gt; &lt;br&gt;{ &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ProductMap{ &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Map( p =&amp;gt; new { &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; pid = p.ID, &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; pcode = p.Name, &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; cid = p.Category.ID &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; this.ForProperty(p =&amp;gt; p.ID).Identity(); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.ForProperty(p =&amp;gt; p.Name).MaxLength(100) &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; .NonUnicode(); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.ForProperty(p =&amp;gt; p.Category).NonNullable(); &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.RegisterInverse(p =&amp;gt; p.Category, &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;&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;&amp;nbsp; c =&amp;gt; c.Products);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This approach is highly recommended, because configuring the &lt;font face="Courier New"&gt;Product&lt;/font&gt; type is now trivial:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;builder.Tables[“dbo.Products”] = new ProductMap();&lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;Summary:&lt;/h3&gt;
&lt;p&gt;As you can see we are planning a lot of enhancements which will allow most core scenarios. &lt;/p&gt;
&lt;p&gt;What do you think? Do you like the API? Are there things you’d like to see look a little different?&lt;/p&gt;
&lt;p&gt;As always we are very keen to hear your feedback.&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 Team, Microsoft. &lt;br&gt;&lt;br&gt;&lt;i&gt;&lt;b&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/b&gt;&lt;/i&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;i&gt;&lt;b&gt;this post&lt;/b&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;&lt;b&gt;. &lt;/b&gt;&lt;/i&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9856565" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/CodeOnly/default.aspx">CodeOnly</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category></item><item><title>Code Only</title><link>http://blogs.msdn.com/efdesign/archive/2009/06/10/code-only.aspx</link><pubDate>Wed, 10 Jun 2009 23:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9724905</guid><dc:creator>efdesign</dc:creator><slash:comments>27</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9724905.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9724905</wfw:commentRss><description>&lt;P&gt;There are currently two ways to get Entity Framework apps up and running, we call these Database First and Model First respectively. &lt;/P&gt;
&lt;P&gt;Database First has been with us since .NET 3.5 SP1, and involves reverse engineering an Entity Data Model from an existing database.&lt;/P&gt;
&lt;P&gt;&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;Model First&lt;/A&gt; is new to Visual Studio 2010/.NET 4.0 and allows you to create an Entity Data Model from scratch and then generate a database and mapping for it.&lt;/P&gt;
&lt;P&gt;However many developers view their Code as their model. &lt;/P&gt;
&lt;P&gt;Ideally these developers just want to write some Domain classes and without ever touching a designer or a piece of XML be able to use those classes with the Entity Framework. &lt;BR&gt;Basically they want to write ‘Code Only’.&lt;/P&gt;
&lt;P&gt;We are pleased to announce that we’ll be shipping a preview of “Code Only” on top of the .NET Framework 4.0 Beta 1 (more on that in the coming days).&lt;/P&gt;
&lt;H5&gt;How it works:&lt;/H5&gt;
&lt;P&gt;To use Code only you simply write some &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 classes&lt;/A&gt;, here is a simple example:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public class Category &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public int ID { get; set; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; public string Name { get; set; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; public List&amp;lt;Product&amp;gt; Products { get; set; } &lt;BR&gt;} &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public class Product &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public int ID { get; set; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; public string Name { get; set; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; public Category Category { get; set; } &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Then write a class that derives from &lt;FONT face="Courier New"&gt;ObjectContext&lt;/FONT&gt; that describes the shape of your model and how you want to access your POCO classes, so something like this: &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;public class MyContext : ObjectContext &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; public MyContext(EntityConnection conn) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; : base(conn){ }&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; public ObjectSet&amp;lt;Category&amp;gt; Categories { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return base.CreateObjectSet&amp;lt;Category&amp;gt;(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; public ObjectSet&amp;lt;Product&amp;gt; Products { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return base.CreateObjectSet&amp;lt;Product&amp;gt;(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt; this persistence / EF aware class could easily be in another assembly so you can keep it separate from your nice pristine domain classes.&lt;/P&gt;
&lt;P&gt;At this point you have everything you need from a CLR perspective, but you won’t be able to use the &lt;FONT face="Courier New"&gt;MyContext&lt;/FONT&gt; class without some EF metadata, which is normally stored in the EDMX file. &lt;/P&gt;
&lt;P&gt;But remember Code-Only means there isn’t an EDMX file. &lt;BR&gt;So where do we get the metadata? &lt;BR&gt;That is where the &lt;FONT face="Courier New"&gt;ContextBuilder&lt;/FONT&gt; class comes in:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;SqlConnection connection = …; // some un-opened SqlConnection &lt;BR&gt;MyContext context = ContextBuilder.Create&amp;lt;MyContext&amp;gt;(connection);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;What is happening here is that the &lt;FONT face="Courier New"&gt;ContextBuilder&lt;/FONT&gt; is looking at the Properties on &lt;FONT face="Courier New"&gt;MyContext&lt;/FONT&gt;, inferring a default Conceptual Model, Storage Model and Mapping by convention, it the uses that metadata plus the &lt;FONT face="Courier New"&gt;SqlConnection&lt;/FONT&gt; you passed in to create an &lt;FONT face="Courier New"&gt;EntityConnection&lt;/FONT&gt;, and finally it constructs an instance of &lt;FONT face="Courier New"&gt;MyContext&lt;/FONT&gt; by passing the &lt;FONT face="Courier New"&gt;EntityConnection&lt;/FONT&gt; to the constructor we created previously.&lt;/P&gt;
&lt;P&gt;Once you have an instance of your context, we ship several extension methods you can use to automatically create a database script, see if the database exists, drops the database, and/or create the database,. For example this code snippet uses two of those extension methods to create the database if it doesn’t already exist.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;if (!context.DatabaseExists()) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.CreateDatabase();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The &lt;FONT face="Courier New"&gt;CreateDatabase&lt;/FONT&gt; call looks at the EF metadata, in particular the Storage Model, aka SSDL, and uses it to produce Database Definition Language (or DDL) which it then executes against against the connection. &lt;/P&gt;
&lt;H5&gt;Overriding Conventions&lt;/H5&gt;
&lt;P&gt;In the examples so far everything is done by convention. This is great if you are happy with our conventions. However you may want to override them, for example to register different keys, use different mappings or use a different inheritance strategy etc.&lt;/P&gt;
&lt;P&gt;To override the convention instead of creating an &lt;FONT face="Courier New"&gt;ObjectContext&lt;/FONT&gt; directly you create an instance of a &lt;FONT face="Courier New"&gt;ContextBuilder&lt;/FONT&gt; that you can configure. &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;var contextBuilder = new ContextBuilder&amp;lt;MyContext&amp;gt;();&lt;/FONT&gt; &lt;BR&gt;&lt;BR&gt;In the first Feature CTP, Code Only provides the ability to override how the key properties are inferred:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;contextBuilder.RegisterKey((Product p) =&amp;gt; p.ID);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This code tells the builder that the key of &lt;FONT face="Courier New"&gt;Product&lt;/FONT&gt; is its &lt;FONT face="Courier New"&gt;ID&lt;/FONT&gt; property.&lt;/P&gt;
&lt;P&gt;When you’ve finished configuring how you want your model and mappings to work in your code, you create an instance of your context, this time by calling Create on the builder instance you have been configuring:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;MyContext context = contextBuilder.Create(connection);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;It is that simple.&lt;/P&gt;
&lt;P&gt;Over time the features of the &lt;FONT face="Courier New"&gt;ContextBuilder&lt;/FONT&gt; will grow so you will be able to setup custom mappings, mark properties as transient, setup up Facets (e.g. &lt;FONT face="Courier New"&gt;MaxLength&lt;/FONT&gt;), change inheritance strategies, link properties that are the inverse of each other together (e.g. &lt;FONT face="Courier New"&gt;product.Category&lt;/FONT&gt; and &lt;FONT face="Courier New"&gt;category.Products&lt;/FONT&gt;) and more. In fact here is an example of the sort of thing we are aiming to support for the next release of the Feature CTP: &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder[“dbo.prds”] =&amp;nbsp; &lt;BR&gt;&amp;nbsp; from c in builder.OfType&amp;lt;Product&amp;gt;() &lt;BR&gt;&amp;nbsp; select new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pcode = p.ID, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.Name, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cat = p.Category.ID &lt;BR&gt;&amp;nbsp; } &lt;BR&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This snippet:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Maps &lt;FONT face="Courier New"&gt;Product&lt;/FONT&gt; entities to the ‘&lt;FONT face="Courier New"&gt;prds&lt;/FONT&gt;’ table. &lt;/LI&gt;
&lt;LI&gt;Maps &lt;FONT face="Courier New"&gt;Product.ID&lt;/FONT&gt; to a ‘&lt;FONT face="Courier New"&gt;pcode&lt;/FONT&gt;’ column. &lt;/LI&gt;
&lt;LI&gt;Maps &lt;FONT face="Courier New"&gt;Product.Name&lt;/FONT&gt; to a ‘&lt;FONT face="Courier New"&gt;Name&lt;/FONT&gt;’ column. &lt;/LI&gt;
&lt;LI&gt;Maps the FK under the &lt;FONT face="Courier New"&gt;Product.Category&lt;/FONT&gt; relationship to the ‘&lt;FONT face="Courier New"&gt;cat&lt;/FONT&gt;’ column. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Here is another example that does basic &lt;A href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx"&gt;TPH&lt;/A&gt; inheritance:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;builder[“dbo.Cars”] = ( &lt;BR&gt;&amp;nbsp; from b in builder.OfTypeOnly&amp;lt;Car&amp;gt;() &lt;BR&gt;&amp;nbsp; select new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id = b.CID.AsKey(), &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.Color, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.Manufacturer, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; disc = “C” &lt;BR&gt;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;).Merge( &lt;BR&gt;&amp;nbsp; from s in builder.OfType&amp;lt;SportsCar&amp;gt;() &lt;BR&gt;&amp;nbsp; select new { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id = s.CID.AsKey(),&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.Color,&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.Manufacturer,&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; disc = “S”,&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hp = s.HorsePower,&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tq = s.Torque &lt;BR&gt;&amp;nbsp; } &lt;BR&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;These two examples just scratch the surface of what we are planning on doing, hopefully though they give you a sense of where we are heading. &lt;/P&gt;
&lt;P&gt;We are super excited about Code Only. But as of right now our plans to support overriding conventions aren’t finalized, so we’d love to get your feedback, this really is your chance to help us get it right.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;A href="http://blogs.msdn.com/alexj" mce_href="http://blogs.msdn.com/alexj"&gt;Alex James&lt;/A&gt;&lt;/B&gt;, &lt;BR&gt;Program Manager, Entity Framework Team, Microsoft &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;B&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/B&gt;&lt;/EM&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;EM&gt;&lt;B&gt;this post&lt;/B&gt;&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;&lt;B&gt;. &lt;/B&gt;&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9724905" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Mapping/default.aspx">Mapping</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/ObjectServices/default.aspx">ObjectServices</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/CodeOnly/default.aspx">CodeOnly</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+Futures/default.aspx">Entity Framework Futures</category></item><item><title>Foreign Keys in the Entity Framework</title><link>http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx</link><pubDate>Mon, 16 Mar 2009 23:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9481955</guid><dc:creator>efdesign</dc:creator><slash:comments>35</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9481955.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9481955</wfw:commentRss><description>&lt;H3&gt;Background&lt;/H3&gt;
&lt;P&gt;A number of months ago &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;we asked&lt;/A&gt; whether Foreign Keys (FKs) in Conceptual and Object models were important.&lt;/P&gt;
&lt;P&gt;The feedback we got indicated that there are a real mix of opinions on the topic. Some people are all for them while others think that FKs pollute the conceptual model. &lt;/P&gt;
&lt;P&gt;The fact that our customers were so divided meant we thought it was important to provide options here. Those who want FKs in their Entities should be able to do so, so they can gain all the benefits that having FKs in your Entities undoubtedly provide. On the other hand customers who are concerned that have FKs in their Entities in someway pollutes their model can continue to use the type of associations we had in .NET 3.5 SP1.&lt;/P&gt;
&lt;P&gt;In the past we've called the .NET 3.5 SP1 style Associations "first class" associations. Which while accurate somehow implies that associations based on FKs in Entities are "second class". In fact when we talked about this new work recently with our MVPs one of the first questions was "are these second class?", which they most definitely are not. &lt;/P&gt;
&lt;P&gt;The fact is these new associations are different but first class nevertheless.&lt;/P&gt;
&lt;H3&gt;So what's been added?&lt;/H3&gt;
&lt;P&gt;In .NET 4.0 we will add support for a new type of association called "FK Associations". &lt;/P&gt;
&lt;P&gt;The way this works is we will allow you to include your FK columns in your entities as "FK properties", and once you have FK Properties in your entity you can create an "FK Association" that is dependent upon those properties. &lt;/P&gt;
&lt;P&gt;Okay so we will have "FK Associations", what are we going to call the older style associations? Obviously saying something like ".NET 3.5 SP1 style Associations" every time isn't ideal. So we are going to call them "Independent Associations".&lt;/P&gt;
&lt;P&gt;The term "Independent Association" resonates for us because they are independently mapped, whereas FK Associations need no mapping, simply mapping the Entity(Set) is sufficient.&lt;/P&gt;
&lt;H3&gt;How do I use an "FK Association"?&lt;/H3&gt;
&lt;P&gt;The real reason so many customers and partners are asking for "FK Associations" is that they significantly simplify some key coding patterns. So much so that we are convinced that for most people "FK Associations" will be an automatic choice going forward.&lt;/P&gt;
&lt;P&gt;Some of the things that are hard with "Independent Associations" are trivially easy using FK Associations. Scenarios as diverse as DataBinding, Dynamic Data, Concurrency Control,&amp;nbsp; ASP.NET MVC Binders, N-Tier etc are all positively impacted.&lt;/P&gt;
&lt;P&gt;Let's have a look at some code snippets that will work with "FK Associations":&lt;/P&gt;
&lt;P&gt;1) Create a new Product and FK Association to an existing Category by setting the FK Property directly:&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;using&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt; (&lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; context = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Context&lt;/SPAN&gt;()) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;{ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Create a product and a relationship to a known category by ID &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Product&lt;/SPAN&gt; p = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Product &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ID = 1, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Name = &lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"Bovril"&lt;/SPAN&gt;, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CategoryID = 13 &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;};&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Add the product (and create the relationship by FK value) &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;context.Products.AddObject(p); &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;context.SaveChanges(); &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;This sort of approach works both for insert and update, and is particular useful for things like databinding, where you often have the new Value of the FK in a grid or something but you don't have the corresponding object, and you don't want to wear the cost of a query to pull back the principal object (i.e. the Category).&lt;/P&gt;
&lt;P&gt;2) Create a new Product and a new FK Association to an existing Category by setting the reference instead:&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Create_new_Product_in_existing_Category_by_reference() &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;{ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; context = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Context&lt;/SPAN&gt;()) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;//Create a new product and relate to an existing category &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Product&lt;/SPAN&gt; p = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Product &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ID = 1, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Name = &lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"Bovril"&lt;/SPAN&gt;, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Category = context.Categories &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Single(c =&amp;gt; c.Name == &lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"Food"&lt;/SPAN&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Note: no need to add the product, because relating &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="COLOR: green"&gt;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// to an existing category does that automatically. &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Also notice the use of the Single() query operator&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// this is new to EF in .NET 4.0 too. &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;context.SaveChanges(); &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;} &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;} &lt;BR&gt;&lt;BR&gt;This programming pattern is not new to the Entity Framework, you could do this in .NET 3.5 SP1. I called it out because it shows you can still write the sort of code you write with Independent Associations even when using FK Associations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3) Update an existing Product without informing the Entity Framework about the original value of the CategoryID (not supported with Independent Associations):&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Edit(&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Product&lt;/SPAN&gt; editedProduct) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;{ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; context = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Context&lt;/SPAN&gt;()) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Create a stand-in for the original entity &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// by just using the ID. Of the editedProduct &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Note: you don't have to provide an existing Category or CategoryID &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;context.Products.Attach( &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; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Product&lt;/SPAN&gt; { ID = editedProduct.ID }); &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;// Now update with new values including CategoryID &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;context.Products.ApplyCurrentValues(editedProduct); &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;context.SaveChanges(); &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;} &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In this example "editedProduct" is a product which has been edited somewhere, this is exactly the sort of the code you might write in the Edit method of a ASP.NET MVC controller, and is a great improvement over the code you have to write using Independent Associations.&lt;/P&gt;
&lt;P&gt;There is much more you can do with FK Associations, but these 3 samples give you a flavor of the sort of coding patterns FK Associations allow. &lt;/P&gt;
&lt;H4&gt;Keeping FKs and References in Sync&lt;/H4&gt;
&lt;P&gt;One thing that hasn't been mentioned so far is that the Entity Framework tries to keep related References and FKs in sync as much as possible. &lt;/P&gt;
&lt;P&gt;When this synchronization occurs depends upon when the Entity Framework is notified of changes, which depends upon the type of Entity Classes involved: be they POCO with Proxies, POCO without Proxies, IPOCO or EntityObjects etc. &lt;/P&gt;
&lt;P&gt;Another post will cover this in more detail.&lt;/P&gt;
&lt;H3&gt;How do I create an "FK Association"?&lt;/H3&gt;
&lt;P&gt;There are a number of ways. &lt;/P&gt;
&lt;P&gt;One mainline scenario is when using the tools to infer a model from a database. We have added an option to choose whether "FK Associations" or "Independent Associations" are generated by default. The same is true if you use EdmGen.exe (i.e. our command line tool).&lt;/P&gt;
&lt;P&gt;The second mainline scenario for creating FK Associations is creating a model from scratch, aka &lt;A href="http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx"&gt;Model First&lt;/A&gt; which is new to .NET 4.0.&lt;/P&gt;
&lt;P&gt;Here are the steps involved:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create two Entities (say Product and Category) that look something like this: &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep1.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep1.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=ProductCategoryStep1 src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep1_thumb.jpg" width=455 height=158 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep1_thumb.jpg"&gt;&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;Add a property that will be the FK Property: i.e. CategoryID &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=ProductCategoryStep2 src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep2_thumb.jpg" width=495 height=227 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep2_thumb.jpg"&gt;&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;Create an association between the two EntityTypes with the correct end multiplicities and NavigationProperty names: &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep3.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep3.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=ProductCategoryStep3 src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep3_thumb.jpg" width=427 height=412 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep3_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Double Click the line between the two Entities, that represents the Association, and add a Referential Integrity Constraint: &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep4.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep4.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=ProductCategoryStep4 src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep4_thumb.jpg" width=374 height=297 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep4_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;This is the step that tells the Entity Framework that the CategoryID is an "FK Property" and that the "CategoryProduct" association is an "FK Association". &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;You end up with something that looks like this: &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep5.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep5.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=ProductCategoryStep5 src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep5_thumb.jpg" width=476 height=235 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ForeignKeysintheEntityFramework_D970/ProductCategoryStep5_thumb.jpg"&gt;&lt;/A&gt;&amp;nbsp; &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;And you are done you've set up an FK Association. Notice that this association doesn't need to be mapped you simply need to make sure you map all the properties of both Entities.&lt;/P&gt;
&lt;P&gt;Very easy.&lt;/P&gt;
&lt;H3&gt;Summary&lt;/H3&gt;
&lt;P&gt;In .NET 4.0 we will add support for FK Properties and FK Associations to the Entity Framework. The existing style Independent Associations will still be possible, but we expect that FK Associations will become most peoples automatic choice because they simplify so many common Entity Framework coding tasks.&lt;/P&gt;
&lt;P&gt;As always we'd love to hear your thoughts on this work.&lt;/P&gt;
&lt;P&gt;&lt;B&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;&lt;/B&gt;Program Manager, Entity Framework Team, Microsoft.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;I&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/I&gt;&lt;/B&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;B&gt;&lt;I&gt;this post&lt;/I&gt;&lt;/B&gt;&lt;/A&gt;&lt;B&gt;&lt;I&gt;. &lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9481955" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/EDM/default.aspx">EDM</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/N-Tier/default.aspx">N-Tier</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Designer/default.aspx">Designer</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/FKs/default.aspx">FKs</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>Customizing Entity Classes in VS 2010</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/22/customizing-entity-classes-with-t4.aspx</link><pubDate>Thu, 22 Jan 2009 22:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9370115</guid><dc:creator>efdesign</dc:creator><slash:comments>23</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9370115.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9370115</wfw:commentRss><description>&lt;P&gt;When VS 2010 ships it will include some significant improvements to our code generation story for the Entity Framework. The basic idea is to make use of T4 templates for code generation and ship strong integration into the Entity Framework Designer to make the experience of customizing those templates as seamless as possible. &lt;BR&gt;&lt;BR&gt;Below Sanjay from our Tools team outlines what will be possible once VS 2010 is released.&lt;/P&gt;
&lt;H3&gt;Customize the code generated by the Entity Designer with T4 templates&lt;/H3&gt;
&lt;P&gt;In Visual Studio 2008 SP1, the ADO.NET Entity Designer generates classes from the CSDL portion of the EDMX file using the &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entityclassgenerator.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entityclassgenerator.aspx"&gt;EntityClassGenerator&lt;/A&gt; APIs. Numerous customers have asked us how to customize the code generation for a variety of scenarios including:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Make the generated ObjectContext internal &lt;/LI&gt;
&lt;LI&gt;Make the generated ObjectContext and Entity classes implement a user-defined interface &lt;/LI&gt;
&lt;LI&gt;Add user-defined CLR attributes to generated ObjectContext and generated Entity classes &lt;/LI&gt;
&lt;LI&gt;Influence generated classes based on structural annotations in CSDL &lt;/LI&gt;
&lt;LI&gt;Generate the ObjectContext and Entity classes into separate files &lt;/LI&gt;
&lt;LI&gt;Generate “proxy classes” for the generated classes &lt;/LI&gt;
&lt;LI&gt;Partially or fully change how classes are generated, maybe even generate additional (non code) artifacts in the project &lt;/LI&gt;
&lt;LI&gt;Completely replace entity framework code generation with custom code &lt;/LI&gt;
&lt;LI&gt;Generate POCO classes from the model to use as a starting point in my applications &lt;/LI&gt;
&lt;LI&gt;Generate self-tracking entity classes &lt;/LI&gt;
&lt;LI&gt;· ... &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;While the SingleFileGenerator techniques described &lt;A href="http://blogs.msdn.com/adonet/archive/2008/01/24/customizing-code-generation-in-the-ado-net-entity-designer.aspx" mce_href="http://blogs.msdn.com/adonet/archive/2008/01/24/customizing-code-generation-in-the-ado-net-entity-designer.aspx"&gt;here&lt;/A&gt; enable some of these scenarios these techniques are generally difficult to implement and install or are tricky to debug and customize.&lt;/P&gt;
&lt;P&gt;In Visual Studio 2010, we plan to give customers the ability to use &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 templates&lt;/A&gt; to generate their classes, and are also planning deep integration with the Entity Designer and Visual Studio to provide a great end-to-end experience.&lt;/P&gt;
&lt;H3&gt;Walkthrough&lt;/H3&gt;
&lt;P&gt;The example below customizes code generation to make the generated classes implement a user-defined interface (e.g. &lt;EM&gt;IValidate&lt;/EM&gt;).&lt;/P&gt;
&lt;H4&gt;Preconditions:&lt;/H4&gt;
&lt;UL&gt;
&lt;LI&gt;User has installed Visual Studio 2010 &lt;/LI&gt;
&lt;LI&gt;User is familiar with customizing T4 templates &lt;/LI&gt;
&lt;LI&gt;User has a C# or a VB console project that targets FX4.0 with an EDMX file in the project &lt;/LI&gt;&lt;/UL&gt;
&lt;H4&gt;Walkthrough:&lt;/H4&gt;
&lt;OL&gt;
&lt;LI&gt;User: opens EDMX file in the Entity Designer. Note that the generated classes are in a child file of the EDMX file (i.e. in Northwind.Designer.cs) &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_4.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=369 alt=image src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_1.png" width=241 border=0 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_1.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;User: right-clicks on an empty area of the designer surface and chooses “&lt;EM&gt;Add New Artifact Generation Item…&lt;/EM&gt;” from the context menu. &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_6.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=328 alt=image src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_2.png" width=250 border=0 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_2.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Visual Studio: displays the standard “&lt;EM&gt;Add New Item&lt;/EM&gt;” dialog and shows a filtered list of items for the user to select from. As expected, the “&lt;EM&gt;Add New Item&lt;/EM&gt;” dialog only shows a list of item templates specific to the current project target framework version, project type and language. &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_8.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=377 alt=image src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_3.png" width=632 border=0 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_3.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;User: selects “&lt;EM&gt;ADO.NET EntityObject Generator&lt;/EM&gt;”, specifies a file name and clicks “&lt;EM&gt;Add"&lt;/EM&gt; &lt;/LI&gt;
&lt;LI&gt;Visual Studio: checks out the project from Source Control if necessary &lt;/LI&gt;
&lt;LI&gt;Visual Studio: sets the “&lt;EM&gt;Custom Tool&lt;/EM&gt;” property of the EDMX file to empty, which will cause the existing .designer.cs file to be deleted &lt;/LI&gt;
&lt;LI&gt;Visual Studio: the VS item template adds a new .tt file to the project in the same project directory as the EDMX file &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_10.png" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_10.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=265 alt=image src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_4.png" width=325 border=0 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_4.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;Visual Studio: configures the new .tt file to process the selected EDMX file. The EDMX file to process is a replaceable parameter in the .tt file, and VS updates it to point to the selected EDMX file. Thus, the .tt file now knows which EDMX file to generate code for. &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_12.png" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_12.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=186 alt=image src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_5.png" width=244 border=0 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_5.png"&gt;&lt;/A&gt; &lt;BR&gt;[Screenshot of .tt file open in the &lt;A href="http://www.t4editor.net/" mce_href="http://www.t4editor.net/"&gt;Clarius T4 Editor Community edition for VS 2008&lt;/A&gt;] &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;User: double-clicks the .tt file in the project to open it in VS10 &lt;/LI&gt;
&lt;LI&gt;User: edits the .tt file in Visual Studio to make every Entity object implement the &lt;EM&gt;IValidate&lt;/EM&gt; interface &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_14.png" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_14.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=148 alt=image src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_6.png" width=244 border=0 mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/CustomizingEntityClasseswithT4_97EE/image_thumb_6.png"&gt;&lt;/A&gt; &lt;BR&gt;[Screenshot of .tt file open in the &lt;A href="http://www.t4editor.net/" mce_href="http://www.t4editor.net/"&gt;Clarius T4 Editor Community edition for VS 2008&lt;/A&gt;] &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;User: saves and closes .tt file &lt;/LI&gt;
&lt;LI&gt;Visual Studio: Transforms the .tt file to produce the generated classes as a child file of the .tt file &lt;/LI&gt;
&lt;LI&gt;User: notes that the generated classes (under the .tt file) implement the IValidate interface as expected &lt;/LI&gt;
&lt;LI&gt;User: switches to the EDMX file in the designer and makes some changes (e.g. add a new entity) &lt;/LI&gt;
&lt;LI&gt;User: saves EDMX file &lt;/LI&gt;
&lt;LI&gt;Visual Studio: Transforms all .tt files in the project that reference the EDMX file. As before, the generated classes are child files of the .tt files &lt;/LI&gt;&lt;/OL&gt;
&lt;H3&gt;Design&lt;/H3&gt;
&lt;P&gt;The design affects multiple parts of the Entity Framework and the Entity Designer and the key changes are described below:&lt;/P&gt;
&lt;H4&gt;Entity Framework Runtime&lt;/H4&gt;
&lt;OL&gt;
&lt;LI&gt;We started by creating C# and VB T4 templates to generate classes from CSDL and EDMX files &lt;/LI&gt;
&lt;LI&gt;Since the T4 engine is installed with Visual Studio and not with the.NET FX runtime, we preprocess the templates as described &lt;A href="https://blogs.msdn.com/garethj/archive/2008/11/11/dsl-2010-feature-dives-t4-preprocessing-rationale.aspx" mce_href="https://blogs.msdn.com/garethj/archive/2008/11/11/dsl-2010-feature-dives-t4-preprocessing-rationale.aspx"&gt;here&lt;/A&gt; and include the compiled code into System.Data.Entity.Design.dll &lt;/LI&gt;
&lt;LI&gt;We added a new class &lt;EM&gt;System.Data.Entity.Design.EntityCodeGenerator&lt;/EM&gt; (in System.Data.Entity.Design.dll ) that generates code using the preprocessed T4 template &lt;/LI&gt;
&lt;LI&gt;Finally, we enhanced a few runtime metadata APIs and added extension methods to load and iterate over models a lot easier. Our T4 templates make heavy use of these new methods. &lt;/LI&gt;&lt;/OL&gt;
&lt;H4&gt;Entity Designer&lt;/H4&gt;
&lt;P&gt;We took the C# and VB T4 templates used by the runtime and changed them to be more “VS friendly” as described below.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;We made the EDMX file name referenced in the T4 templates a replaceable parameter &lt;/LI&gt;
&lt;LI&gt;We created a wizard (with no GUI) that is launched by Visual Studio when the item is added to the project. The wizard does 2 things: 
&lt;OL&gt;
&lt;LI&gt;updates the EDMX file name referenced in the T4 templates and &lt;/LI&gt;
&lt;LI&gt;sets the “&lt;EM&gt;Custom Tool&lt;/EM&gt;” property of the EDMX file to empty &lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;
&lt;LI&gt;We rolled up the T4 templates (and wizard) into standard C# and VB Visual Studio item template which are installed with VS 2010; this makes them show up in the “&lt;EM&gt;Add New Item&lt;/EM&gt;” dialog in Visual Studio &lt;/LI&gt;
&lt;LI&gt;We added a new context menu to the designer surface to launch the “&lt;EM&gt;Add New Item&lt;/EM&gt;” dialog and also added code to only show VS item templates whose names start with the prefix &lt;EM&gt;ADONETArtifactGenerator_&lt;/EM&gt; &lt;/LI&gt;
&lt;LI&gt;Our design ensures that user installed VS item templates in &lt;EM&gt;%MyDocuments%&lt;/EM&gt; as well as the VS item templates we ship in box show up in the “&lt;EM&gt;Add…New…Item&lt;/EM&gt;” dialog (per the template name prefix rule above) &lt;/LI&gt;
&lt;LI&gt;We added code to the designer that finds all .tt files related to an EDMX file and automatically transform them when the EDMX file is saved. &lt;/LI&gt;
&lt;LI&gt;Finally, we added a new property called “&lt;EM&gt;Process related T4 templates on Save&lt;/EM&gt;” on the designer surface to let users control whether or not to transform .tt files related to the EDMX file on save. &lt;/LI&gt;&lt;/OL&gt;
&lt;H4&gt;Multi Targeting considerations&lt;/H4&gt;
&lt;P&gt;As many of you are aware, VS 2010 allows developers to target FX4.0 as well as FX3.5 (and older runtimes). The T4 templates that we ship in the Visual Studio box generate code that works with the Entity Framework in .NET FX 4.0. This means the VS item templates we ship in the box will not be available for projects that target FX3.5.&lt;/P&gt;
&lt;P&gt;However, it is certainly possible (and supported) for users to create new T4 templates (and new VS item templates) that generate code from an EDMX file in projects that target FX3.5 and light up in the same experience. In fact, we might release some new templates ourselves later, on CodeGallery perhaps.&lt;/P&gt;
&lt;H4&gt;How can 3&lt;SUP&gt;rd&lt;/SUP&gt; parties plug in?&lt;/H4&gt;
&lt;P&gt;Since our design is based upon VS item templates that wrap T4 templates, we have opened the door to let 3&lt;SUP&gt;rd&lt;/SUP&gt; party code generators participate in the end-to-end experience. Our contract is straight forward and easy to implement:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a (C# or VB) T4 template to generate code as you desire. The T4 templates we ship in the box can be invaluable points of reference as you roll your own. &lt;/LI&gt;
&lt;LI&gt;Make the EDMX reference in your .tt file a replaceable parameter by calling it &lt;EM&gt;$edmxInputFile$&lt;/EM&gt; like we do in our .tt file. &lt;/LI&gt;
&lt;LI&gt;Wrap the .tt file in a VS item template. This is pretty easy and well documented on &lt;A href="http://msdn.microsoft.com/en-us/library/ms247069(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms247069(VS.80).aspx"&gt;MSDN&lt;/A&gt;. You can also use the &lt;A href="http://msdn.microsoft.com/en-us/library/ms185318(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms185318(VS.80).aspx"&gt;Export Template wizard&lt;/A&gt; included Visual Studio. Also specify additional VS item template settings such as target framework, project type, etc &lt;/LI&gt;
&lt;LI&gt;Prefix the name of your .vstemplate file with &lt;EM&gt;ADONETArtifactGenerator_&lt;/EM&gt; if you want your VS item template to show up in the “&lt;EM&gt;Add New Item&lt;/EM&gt;” dialog when it is launched from the context menu in the Entity Designer. &lt;/LI&gt;
&lt;LI&gt;You can use the wizard we ship in Visual Studio to do parameter replacement in your VS item template by adding the following to your .vstemplate file: &lt;BR&gt;&lt;BR&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;WizardExtension&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;Assembly&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;Microsoft.Data.Entity.Design, Version=10.0.0.0, Culture=neutral,&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;PublicKeyToken=b03f5f7f11d50a3a &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;Assembly&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;FullClassName&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.AddArtifactGeneratorWizard&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;FullClassName&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;WizardExtension&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;BR&gt;Of course, you can also create your own wizard that does custom processing when the item is added to the project as described &lt;A href="http://msdn.microsoft.com/en-us/library/ms185301(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms185301(VS.80).aspx"&gt;here&lt;/A&gt;. &lt;/LI&gt;
&lt;LI&gt;Create a &lt;A href="http://msdn.microsoft.com/en-us/library/aa992029(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa992029(VS.80).aspx"&gt;VSCONTENT&lt;/A&gt; file and zip up your custom item template &amp;amp; related files into a &lt;A href="http://msdn.microsoft.com/en-us/library/ms246580(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms246580(VS.80).aspx"&gt;Visual Studio Content Installer (.vsi)&lt;/A&gt; file &lt;/LI&gt;
&lt;LI&gt;Upload the .vsi file someplace your customers can download it from &lt;/LI&gt;
&lt;LI&gt;Visual Studio already knows how to install .vsi files and everything you need is already available in Visual Studio. &lt;/LI&gt;&lt;/OL&gt;
&lt;H3&gt;A few key takeaways:&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;This design lets the EF team release new T4 templates outside the usual Visual Studio and .NET FX ship cycles and the experience to consume them is exactly the same.&lt;/LI&gt;
&lt;LI&gt;There are several excellent resources on the web that describe advanced T4 template scenarios and our design enables them. In fact, we expect users to leverage these resources while creating new T4 templates or customizing the ones we ship. For example, code in a custom T4 template can use the &lt;A href="http://msdn.microsoft.com/en-us/library/envdte(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/envdte(VS.80).aspx"&gt;EnvDTE APIs&lt;/A&gt; to access the project system and generate outputs to multiple files.&lt;/LI&gt;
&lt;LI&gt;Over time, we expect to blog about some of these advanced scenarios and also work with MVPs, industry experts and Patterns &amp;amp; Practices to provide guidance to customers in a manner similar to the &lt;A href="http://msdn.microsoft.com/en-us/vsts2008/aa718948.aspx" mce_href="http://msdn.microsoft.com/en-us/vsts2008/aa718948.aspx"&gt;Guidance Automation Toolkit&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;Custom T4 templates can generate anything you want, not just code. For example, we have an internal prototype of a T4 template that iterates over a model and generates an HTML file with a nicely formatted report of the entities and associations in the model&lt;/LI&gt;
&lt;LI&gt;VS item templates can add multiple files to your project (more details &lt;A href="http://msdn.microsoft.com/en-us/library/ms247115(VS.80).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms247115(VS.80).aspx"&gt;here&lt;/A&gt;). This means your custom item templates can include all kinds of files (e.g. workflow files, multiple T4 files, pre-canned code files, etc). For example, you can easily imagine a 3&lt;SUP&gt;rd&lt;/SUP&gt; party VS item template that adds 2 .tt files in your project that process the same EDMX file but generate different kinds of outputs.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;We hope this gives you an overview of our design and intent of this feature and we would love to hear your comments.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sanjay Nagamangalam,&lt;/STRONG&gt; &lt;BR&gt;Lead PM, ADO.NET Entity Designer&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/EM&gt;&lt;/STRONG&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;FONT color=#4c6d7e&gt;this post&lt;/FONT&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;&lt;EM&gt;. &lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9370115" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Customization/default.aspx">Customization</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Designer/default.aspx">Designer</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx</link><pubDate>Wed, 07 Jan 2009 23:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9290047</guid><dc:creator>efdesign</dc:creator><slash:comments>21</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9290047.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9290047</wfw:commentRss><description>&lt;P&gt;Today the Entity Framework, and more specifically the Entity Data Model, have a limited notion of Functions.&lt;/P&gt;
&lt;P&gt;We are currently restricted to Function Imports that allow stored procedures to be invoked, and Canonical / Store Functions for database independent and database specific functions respectively.&lt;/P&gt;
&lt;P&gt;Now however we want to &lt;SPAN style="mso-fareast-language: ja"&gt;support functions defined, not just declared, in the EDM (&lt;A href="http://blogs.msdn.com/alexj/archive/2008/11/24/edm-misconceptions.aspx" mce_href="http://blogs.msdn.com/alexj/archive/2008/11/24/edm-misconceptions.aspx"&gt;aka. the CSDL&lt;/A&gt;). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="mso-fareast-language: ja"&gt;An example would be: &lt;/SPAN&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none; mso-outline-level: 1" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: #a31515; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;Function&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: red; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;=&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;"&lt;SPAN style="COLOR: blue"&gt;GetAge&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ReturnType&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Edm.Int32&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: #a31515; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;Parameter&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt; &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: red; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;=&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;"&lt;SPAN style="COLOR: blue"&gt;Person&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Model.Person&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; /&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: #a31515; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;DefiningExpression&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&amp;gt;&amp;nbsp;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;FONT color=#000000&gt;Edm.DiffYears(Edm.CurrentDateTime(), Person.Birthday)&lt;/FONT&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: #a31515; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;DefiningExpression&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: ; COLOR: #a31515; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;Function&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&amp;gt; &lt;/SPAN&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="mso-no-proof: yes"&gt;Here are some things to notice:&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;The DefiningExpression is eSQL.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;The function can have zero or more parameters.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;The Function must have a return type.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;Function Parameters are referenced directly by Name in the DefiningExpression: meaning there is no parameter denoting prefix like @. This means you must be careful to choose parameter names that don't collide with identifiers you need to use in the rest of eSQL expression.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;Unlike functions in SSDL, functions in CSDL only support In bound Parameters (i.e &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Mode&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;=&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;"&lt;SPAN style="COLOR: blue"&gt;In&lt;/SPAN&gt;") &lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;because otherwise they become non-composable.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;For this reason the &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Mode&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;of a parameter cannot be set in CSDL (it is always &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Mode&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;=&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;"&lt;SPAN style="COLOR: blue"&gt;In&lt;/SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;).&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 1"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;Functions are declared as Global Items and are declared&amp;nbsp;within the &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Schema&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt; &lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;element. As such there identity is made up of the Schema's namespace and the function name.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;The function parameters and return type can be any of the following:&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;A scalar type or collection of scalar types.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;An entity type or collection of entity types.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;A complex type or collection of complex types.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;A row type or collection of row types (See below).&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;A ref type or collection of ref types.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;Functions with a DefiningExpression do not require mapping, since the eSQL expression is composed out of eSQL fragments that are already mapped.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;Functions without a DefiningExpression are simply declarations. Today the Entity Framework doesn't complain when loading a CSDL with such a function, but you can't invoke it. In the future these functions might be used to support mapping Table Value Functions in the store to functions in the Conceptual Model.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;Since it is trivial in eSQL to create arbitrary un-named types, imagine a projection that projects 3 of the properties from an Entity, we now need a mechanism for defining these "RowTypes" inline, so that they can be used when defining Function Parameters and ReturnTypes. For example:&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-language: ja"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-language: ja"&gt;Parameter&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;=&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;"&lt;SPAN style="COLOR: blue"&gt;Coordinate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;RowType&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt; &lt;BR&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Property&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;=&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;"&lt;SPAN style="COLOR: blue"&gt;X&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt; &lt;BR&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Y&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt; &lt;BR&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Z&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;RowType&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Parameter&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;Since eSQL is primarily set based, we also need a way of defining parameters and return types that are collections of RowTypes: &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-language: ja"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-language: ja"&gt;Parameter&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;=&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;"&lt;SPAN style="COLOR: blue"&gt;Coordinates&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;CollectionType&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;RowType&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt; &lt;BR&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Property&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; &lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: red; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;=&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;"&lt;SPAN style="COLOR: blue"&gt;X&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt; &lt;BR&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Y&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt; &lt;BR&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Property&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Z&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Nullable&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;RowType&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt; &lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;CollectionType&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #a31515; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;Parameter&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Using the Function via eSQL:&lt;/H3&gt;
&lt;P&gt;It is trivial to use the function via eSQL. For example:&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: #17365d" new?;="new?;" courier="courier" mso-themecolor:="mso-themecolor:" mso-themeshade:="mso-themeshade:" 191?="191?" text2;="text2;" JA;="JA;" mso-fareast-language:="mso-fareast-language:"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: " new?;="new?;" courier="courier" mso-fareast-language:="mso-fareast-language:" JA?="JA?"&gt; Namespace.GetAge(p) &lt;BR&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191"&gt;FROM&lt;/SPAN&gt; Container.People &lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191"&gt;AS&lt;/SPAN&gt; P &lt;BR&gt;&lt;SPAN style="COLOR: #17365d; mso-themecolor: text2; mso-themeshade: 191"&gt;WHERE&lt;/SPAN&gt; P.Firstname = &lt;SPAN style="COLOR: red"&gt;‘Jim’ &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;P&gt;Here we get Jim's age, assuming of course there is only one Jim!&lt;/P&gt;
&lt;P&gt;It is also possible to compose functions together, you must simply ensure return types and target parameter types are the same (in the case of named types) or structurally equivalent (in the case of row types or collections of row types).&lt;/P&gt;
&lt;P&gt;Things get a little trickier when you are dealing with functions that return sets, for example imagine a function that returns someone's friends, used in conjunction with the GetAge function:&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: #1f497d" new?;="new?;" courier="courier" mso-themecolor:="mso-themecolor:" text2?="text2?"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: " courier="courier" new??="new??"&gt; &lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;VALUE&lt;/SPAN&gt; (F) &lt;BR&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;FROM&lt;/SPAN&gt; Container.People &lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;AS&lt;/SPAN&gt; P &lt;BR&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;CROSS&lt;/SPAN&gt; &lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;APPLY&lt;/SPAN&gt; Namespace.GetFriends(P) &lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;AS&lt;/SPAN&gt; F &lt;BR&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;WHERE&lt;/SPAN&gt; Namespace.GetAge(P) &amp;gt; 21 &lt;/SPAN&gt;
&lt;P&gt;Here we get all the friends of people older than 21.&lt;/P&gt;
&lt;P&gt;As you can see to do this sort of thing you need a crash course in eSQL. &lt;/P&gt;
&lt;H3&gt;Using the Function via LINQ:&lt;/H3&gt;
&lt;P&gt;It is also possible to use these functions in LINQ, but this does require a extra step to create an appropriate stub function in the CLR.&lt;/P&gt;
&lt;P&gt;This solution is based on the techniques described &lt;A href="http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx"&gt;here&lt;/A&gt;, and involves creating a Stub function in the CLR language of your choice, and annotating it something like this:&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN-BOTTOM: 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;[&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EdmFunction&lt;/SPAN&gt;&lt;/SPAN&gt;(&lt;FONT color=#ff0000&gt;"Namespace"&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;"GetAge"&lt;/FONT&gt;)] &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt; &lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;static &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;GetAge(&lt;SPAN style="COLOR: #2b91af"&gt;Person&lt;/SPAN&gt; p) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;{&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;throw new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #31849b; mso-themecolor: accent5; mso-themeshade: 191"&gt;NotSupportedException&lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d; mso-themecolor: text2"&gt;(…); &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;}&lt;/SPAN&gt;&lt;SPAN style="mso-fareast-language: ja"&gt; &lt;/SPAN&gt;
&lt;P&gt;The Entity Framework uses the signature of the function and the EdmFunction attribute to map calls to this function when encountered to the appropriate Model Defined Function.&lt;/P&gt;
&lt;P&gt;Once you have this stub it is then trivial to use it in a LINQ query like this:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: ; COLOR: blue; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt; peopleOver21 = &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/SPAN&gt; p &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ctx&lt;/SPAN&gt;.People &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;/SPAN&gt; GetAge(p) &amp;lt; 21 &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: ; FONT-SIZE: 10pt" new?;="new?;" courier="courier" yes?="yes?" mso-no-proof:="mso-no-proof:"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/SPAN&gt; p; &lt;/SPAN&gt;
&lt;P&gt;Indeed if you are familiar with LINQ you will probably find composing functions together a lot easier too:&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt; friendOfPeopleOver21 = &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/SPAN&gt; p &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ctx&lt;/SPAN&gt;.People &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;from&lt;/SPAN&gt;&amp;nbsp;&lt;FONT color=#000000&gt;f&lt;/FONT&gt; &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt;&amp;nbsp;&lt;FONT color=#000000&gt;GetFriends(p)&lt;/FONT&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;/SPAN&gt; GetAge(p) &amp;lt; 21 &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/SPAN&gt; f; 
&lt;P mce_keep="true"&gt;&lt;/SPAN&gt;Notice that the CLR functions don't need to be directly callable, in the example above the CLR stub throws an exception if called directly. &lt;/P&gt;
&lt;P&gt;However the existence of the stub allows you to create LINQ expressions that compile correctly, and then at runtime, when used in a LINQ to Entities query, the function call is simply translated by the entity framework into a query that runs in the database.&lt;/P&gt;
&lt;H3&gt;Summary&lt;/H3&gt;
&lt;P&gt;As you can see Model Defined Function's are very powerful, and this post has barely scratched the surface of possibilities they open up.&lt;/P&gt;
&lt;P&gt;The Entity Framework team would love to hear your comments.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;A href="http://blogs.msdn.com/alexj" mce_href="http://blogs.msdn.com/alexj"&gt;Alex James&lt;/A&gt;&lt;/STRONG&gt;&amp;nbsp; &lt;BR&gt;Program Manager, &lt;BR&gt;Entity Framework Team&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;this post&lt;/A&gt;.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9290047" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/EDM/default.aspx">EDM</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Linq+to+Entities/default.aspx">Linq to Entities</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Functions/default.aspx">Functions</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/eSQL/default.aspx">eSQL</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>Pluralization</title><link>http://blogs.msdn.com/efdesign/archive/2008/12/02/pluralization.aspx</link><pubDate>Tue, 02 Dec 2008 03:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9162260</guid><dc:creator>efdesign</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9162260.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9162260</wfw:commentRss><description>&lt;p&gt;Unfortunately in&amp;nbsp;the current version of the Entity Framework, which ships in .NET 3.5 SP1,&amp;nbsp;we don't make any attempt to Singularize or Pluralize names when reverse engineering a model from the database. &lt;/p&gt;
&lt;p&gt;So if, for example, your database has a table called Orders you will get an EntityType called Orders too, which clearly doesn't make for the most read-able code:&lt;/p&gt;
&lt;div class="codeblock"&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Orders &lt;/span&gt;order = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Orders&lt;/span&gt;(); &lt;font color="#008000"&gt;//? why not just Order ?&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;LINQ to SQL does a better job here, because it ships with simple but effective pluralization and singuralization services, that for the most part produces names you would expect.&lt;/p&gt;
&lt;p&gt;Unfortunately the lack of a similar feature in the Entity Framework, means that generally the first thing you do after you've reverse engineered a model with the Entity Framework is fix-up all the silly names.&lt;/p&gt;
&lt;p&gt;Now from the perspective of someone who delivers plenty of Entity Framework demos, this is quite embarrassing!&amp;nbsp; &lt;/p&gt;
&lt;p&gt;But of course the real problem here is that it is time consuming and error prone for all but the most trivial models. &lt;/p&gt;
&lt;p&gt;&lt;u&gt;Solution:&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;the next version&amp;nbsp;we have added basic pluralization support. This support only really handles English, and here's why:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Creating language and culture aware services is very hard, and we thought it would be better to spend our time working on the core of the Entity Framework.&lt;/li&gt;
&lt;li&gt;These sort of services are very general and as such we think that they belong elsewhere, maybe inside Windows itself?&lt;/li&gt;
&lt;li&gt;We have made the PluralizationService class public so you are free to write your own. &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Our default English language pluralization is then used whenever you generate a model from a database or visa-versa (see &lt;a href="http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx"&gt;model first&lt;/a&gt;) to help produce appropriate names. &lt;/p&gt;
&lt;p&gt;And for command line users familiar with &lt;b&gt;EdmGen.exe&lt;/b&gt; there is a new &lt;b&gt;/pluralize&lt;/b&gt; switch also.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Basic Pluralization Rules:&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;So how does the Entity Framework use this pluralization service?&lt;/p&gt;
&lt;p&gt;Well it calls the service to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Singularize EntityType names&lt;/li&gt;
&lt;li&gt;Singularize NavigationProperty names that point to 0-1 entities&lt;/li&gt;
&lt;li&gt;Pluralize EntitySet names&lt;/li&gt;
&lt;li&gt;Pluralize NavigationProperty names that point to 0-* entities&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;It turns out that if you do this, you get the model you are looking for most of the time.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;The Pluralization APIs:&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;So far we've talked about default behavior, if however you need more control, for example if you want to specify custom pluralization rules or a create a completely custom service, you have to drop down to the API level.&lt;/p&gt;
&lt;p&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;&lt;font color="#000000"&gt;Everything revolves around a newly added public &lt;/font&gt;PluralizationService &lt;/span&gt;class that looks something like this:&lt;/p&gt;
&lt;div class="codeblock"&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;abstract&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;PluralizationService &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;{&amp;nbsp;&lt;br&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&lt;font color="#000000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;/span&gt;public&lt;/span&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;PluralizationService&lt;/span&gt; CreateService(&lt;span style="color: rgb(43, 145, 175);"&gt;CultureInfo&lt;/span&gt; culture);&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;abstract&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; Pluralize(&lt;span style="color: blue;"&gt;string&lt;/span&gt; word); &lt;br&gt;&lt;/span&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;abstract&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; Singularize(&lt;span style="color: blue;"&gt;string&lt;/span&gt; word); &lt;br&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;} 
&lt;p mce_keep="true"&gt;&lt;/p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;As you can see classes that derive from &lt;span style="color: rgb(43, 145, 175);"&gt;PluralizationService &lt;/span&gt;can singularize and pluralize words. 
&lt;p&gt;You can also ask the &lt;span style="color: rgb(43, 145, 175);"&gt;PluralizationService &lt;/span&gt;to create a concrete &lt;span style="color: rgb(43, 145, 175);"&gt;PluralizationService &lt;/span&gt;for you based on Culture (as mentioned previously only "en" based cultures are supported out of the box).&lt;/p&gt;
&lt;p&gt;Here is a little code that gets hold of the built-in English Language pluralization services, configures it so "Child" will pluralize to "Children" and then checks that it pluralizes correctly.&lt;/p&gt;
&lt;div class="codeblock"&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;PluralizationService&lt;/span&gt; pluralizationService =&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PluralizationService&lt;/span&gt;.CreateService( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;CultureInfo&lt;/span&gt;(&lt;font color="#ff0000"&gt;"en-US"&lt;/font&gt;));&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ICustomPluralizationMapping &lt;/span&gt;mapping =&amp;nbsp; &lt;br&gt;&amp;nbsp; pluralizationService &lt;font color="#0000ff"&gt;as&lt;/font&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ICustomPluralizationMapping&lt;/span&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;font color="#008000"&gt;&lt;font color="#000000"&gt;if (mapping != null)&lt;/font&gt; // it shouldn't be but just checking &lt;br&gt;&lt;/font&gt;{ &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;font color="#008000"&gt;//Specifying the child pluralizes as children &lt;br&gt;&lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mapping.Add(&lt;font color="#ff0000"&gt;"Child"&lt;/font&gt;, &lt;font color="#ff0000"&gt;"Children"&lt;/font&gt;); &lt;br&gt;} &lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Debug&lt;/span&gt;.Assert(pluralizationService.Pluralize(&lt;font color="#ff0000"&gt;"Child"&lt;/font&gt;) == &lt;font color="#ff0000"&gt;"Children"&lt;/font&gt;);&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;You can use your pluralization service in Model Generation (i.e. the step that produces CSDL and MSL from SSDL) by handing your pluralization service to the &lt;span style="color: rgb(43, 145, 175);"&gt;EntitySchemaModelGenerator&lt;font color="#000000"&gt;:&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="codeblock"&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; color: rgb(118, 146, 60);" mso-no-proof:="" new?;="" courier="" 191?="" mso-themeshade:="" accent3;="" yes;="" mso-themecolor:=""&gt;&lt;font color="#008000"&gt;//Create an EDM from SSDL generator &lt;br&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EntityModelSchemaGenerator&lt;/span&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; generator = &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;EntityModelSchemaGenerator&lt;/span&gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; storageModel,&lt;span style="color: rgb(163, 21, 21);"&gt;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "MyNamespace"&lt;/span&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(163, 21, 21);"&gt;"MyContainer&lt;/span&gt;",&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pluralizationService); 
&lt;p mce_keep="true"&gt;&lt;/p&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; color: rgb(118, 146, 60);" mso-no-proof:="" new?;="" courier="" 191?="" mso-themeshade:="" accent3;="" yes;="" mso-themecolor:=""&gt;&lt;font color="#008000"&gt;//Generate CSDL and MSL (in memory)&lt;/font&gt;&lt;/span&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;br&gt;generator.GenerateMetadata();&lt;span style="color: rgb(118, 146, 60);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;The resulting CSDL will have been pluralized/singularized as described in the earlier rules using the provided pluralization service. &lt;br&gt;&lt;br&gt;See &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entitymodelschemagenerator.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entitymodelschemagenerator.aspx"&gt;this&lt;/a&gt; for more information on the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entitymodelschemagenerator.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entitymodelschemagenerator.aspx"&gt;EntityModelSchemaGenerator&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Summary&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;So as you can see we've added simple pluralization capabilities, akin to those found in LINQ to SQL, that will reduce the amount of work required to create meaningful models. &lt;/p&gt;
&lt;p&gt;And to top it off, the solution we've created is easy to customize and public so you can probably use this for other things too!&lt;/p&gt;
&lt;p&gt;As always we are very keen to hear what you think. &lt;br&gt;&lt;br&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 &lt;br&gt;Microsoft&lt;/p&gt;
&lt;p&gt;&lt;b&gt;UPDATE:&lt;/b&gt;&amp;nbsp;A number of people have asked whether pluralization can be turned off, because the post doesn't make this clear. The&amp;nbsp;answer is absolutely, pluralization is definitely optional, in Visual Studio&amp;nbsp;this is&amp;nbsp;as&amp;nbsp;simple as checking/unchecking a checkbox in the wizard, and for EDMGen.exe&amp;nbsp;you have to opt-in for pluralization with&amp;nbsp;the&amp;nbsp;&lt;b&gt;/pluralize&lt;/b&gt;&amp;nbsp;commandline switch.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/i&gt;&lt;/b&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;b&gt;&lt;i&gt;this post&lt;/i&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;i&gt;.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9162260" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Metadata/default.aspx">Metadata</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Pluralization/default.aspx">Pluralization</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>N-Tier Improvements for Entity Framework</title><link>http://blogs.msdn.com/efdesign/archive/2008/11/20/n-tier-improvements-for-entity-framework.aspx</link><pubDate>Thu, 20 Nov 2008 08:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9127479</guid><dc:creator>efdesign</dc:creator><slash:comments>51</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9127479.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9127479</wfw:commentRss><description>&lt;P mce_keep="true"&gt;The first version of Entity Framework provides convenient ways to load, manipulate and persist objects and relationships. As with many other O/RMs, Entity Framework has a state manager that tracks every change made. Existing objects are typically loaded first from the database, later modified, and finally the changes are saved back to the store. &lt;/P&gt;
&lt;P&gt;Another feature, full graph serialization, makes it very easy for developers to ship around object graphs representing snapshots of the &lt;B&gt;current state&lt;/B&gt; of the world, across execution boundaries. &lt;/P&gt;
&lt;P&gt;The next version of Entity Framework will also support Persistence Ignorance. Therefore object graphs can now be made of &lt;A href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object" mce_href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object"&gt;POCO&lt;/A&gt; instances, which &lt;A href="http://www.pluralsight.com/community/blogs/aaron/archive/2008/05/13/50934.aspx" mce_href="http://www.pluralsight.com/community/blogs/aaron/archive/2008/05/13/50934.aspx"&gt;WCF now also supports&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Nonetheless, there is a task that belongs in any N-Tier application that still requires a great amount of work for developers using EF:&amp;nbsp; decoding messages that represent &lt;B&gt;state changes&lt;/B&gt; performed by the client, meant to be processed or persisted by the service. &lt;/P&gt;
&lt;P&gt;The major pain point in the first version is the number of intricate steps a program needs to perform in order to setup the state manager in the appropriate state according to the changes encoded in the message. For instance, for any but the simplest scenarios, in order to use the basic graph manipulations APIs in ObjectContext, like AddObject and AttachTo, it is necessary to “shred” the object graphs contained in the message, which destroys important information about relationships between object instances that therefore has to be kept somewhere else (as an illustration of this approach, see Danny Simmons’s EntityBag in project &lt;A href="http://code.msdn.microsoft.com/entitybag" mce_href="http://code.msdn.microsoft.com/entitybag"&gt;Perseus&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;In addition, given that the message typically contains all the necessary information and that concurrency is usually a concern, the program shouldn’t have to re-query the database. Instead, it should be easier to “tell” the state manager about the original state (that came from the database previously) and about what changes were made.&lt;/P&gt;
&lt;P&gt;There are a few approaches to N-Tier that are very popular in the industry. Customers using Entity Framework for the first time often carry the expectation that it will support a similar experience:&lt;/P&gt;
&lt;H3&gt;DataSet &lt;/H3&gt;
&lt;P&gt;The original ADO.NET data access technology includes the DataSet, a versatile data cache that can be serialized as XML and be used to transport collections of rows and relationships and, also &lt;A href="http://msdn.microsoft.com/en-us/library/ms172088(VS.71).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms172088(VS.71).aspx"&gt;diffgrams&lt;/A&gt; representing changes. &lt;/P&gt;
&lt;P&gt;DataSets make many N-Tier scenarios extremely easy to implement, and over time, have proven helpful for many customers. In spite of this, they are not appropriate for some scenarios and architectural patterns:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;The lack of a widely accepted standard serialization format has hindered the development of implementations that could produce or consume datasets in other platforms.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Diffgrams represent sets of CREATE, UPDATE and DELETE operations of arbitrary depth, which is not adequate for architectural patterns that conceive operations with more constrained semantics (i.e. PlaceOrder, CreateCustomer).&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;No simple ways to control the application of batch CUD operations contained in diffgrams makes them unsuitable any time there is a trust boundary between the client and the server. &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Also, the data-centered perspective of DataSets leads to an anti-pattern known as the “anemic domain model”, which is characterized by a separation between the data aspect and the behavioral aspect of domain objects.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H3&gt;Data Transfer Objects&lt;/H3&gt;
&lt;P&gt;The approach typically used in the DDD and SOA communities to address&amp;nbsp; multi-tier scenarios is to hand-build a service with well defined operation semantics together with the a conceptual message format, usually composed of &lt;A href="http://msdn.microsoft.com/en-us/library/ms978717.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms978717.aspx"&gt;data transfer objects&lt;/A&gt; (DTOs).&amp;nbsp; Implementing DTOs often also involves writing the logic that translates DTOs back and forth to persistent objects.&lt;/P&gt;
&lt;P&gt;Here is a simplified set of rules that characterizes the use of DTOs: &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Actual entities are not serialized, just DTOs, which are value-only objects (without behavior) are exposed in the boundaries.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;The client does not depend on the types defined on the server. The shapes of the DTOs are the sole contract, and the types used in the client are for the client only.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;The context or container is not sent together with the message.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;The service decides what to do with the contents of the message. It is not the message who decides (as an extreme counter example, imagine a message that tells the service to delete all the contents of the database).&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Those rules are especially important in SOA scenarios, in which the client and the server can be separated by a trust boundary, such as the one that exists between two different companies. &lt;/P&gt;
&lt;P&gt;There are other permutations of layered architectures, though, in which the level of decoupling that DTOs provide may not justify the increased complexity, for example: &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;A multi-tier application in which the client is fully trusted.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;A rich internet application in which an infrastructure service is purely used for data persistence (is by design a CRUD-only service) and therefore types exposed do not contain behavior anyway.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Any architecture in which the persistence framework is actually used to provide and manage DTOs and not the actual entities. &lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H3&gt;REST&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/data/bb931106.aspx" mce_href="http://msdn.microsoft.com/en-us/data/bb931106.aspx"&gt;ADO.NET Data Services&lt;/A&gt; provides a rich framework that developers can easily use to expose any Entity Data Model as a REST-style resource collection. Simple HTTP verbs like GET, PUT, POST and DELETE are used in combination with URIs to represent CRUD operations against the persistence service.&lt;/P&gt;
&lt;P&gt;This pattern is suitable for many applications and can easily be combined with service operations with richer semantics in the same application. &lt;/P&gt;
&lt;P&gt;ADO.NET Data Services, however, may not be compelling for those customers who want to define their services as operations with richer semantics entirely. &lt;/P&gt;
&lt;H2&gt;Goals&lt;/H2&gt;
&lt;P&gt;ADO.NET Data Services goes a long way addressing the needs of customers doing RESTful services, and so there is no need for us to improve Entity Framework experience on that space.&lt;/P&gt;
&lt;P&gt;With the N-Tier improvements for Entity Framework, we want to address some of the same problem space as DataSet, but we want to avoid the primary issues with it. &lt;/P&gt;
&lt;P&gt;Ideally, we would like to provide building blocks that are appealing for developers building solutions on a wide range of architectures. For instance, we would like to provide fine enough control for DTO proponents, but at the same time reduce the level of pain that those trying to address simpler scenarios experience today. &lt;/P&gt;
&lt;H2&gt;Design&lt;/H2&gt;
&lt;P&gt;If we just wanted to provide a DataSet like experience on top of Entity Framework, the most straightforward (although very expensive to test) way would probably be based on full serialization of the state manager. Basically, the internal representation of ObjectStateManager includes collections of objects to be deleted, inserted, and modified, and also relationships to be added and deleted, as well as objects and relationships that should remain unchanged. &lt;/P&gt;
&lt;P&gt;Such a model would lead to very fine grain control of the state manager, but you would lose some of the benefits of operating on the domain objects and the higher level APIs. For instance, it would make it extremely easy for the program to set the state manager in a completely invalid state.&lt;/P&gt;
&lt;P&gt;An alternative representation for such an experience would be to ship a “change log” containing the history of all operations performed on the client. This representation has the disadvantage of being more verbose than the previous one, but it would make “point in time” rollbacks pretty easy to implement.&lt;/P&gt;
&lt;P&gt;Besides these two, there are a few more interesting generic representations for changes in a graph, but in general, they all suffer from the same disadvantage: providing a solution for them does not give the user the level of control that the most complicated scenarios and sophisticated patterns require. &lt;/P&gt;
&lt;P&gt;Based on this fact, we decided to adopt the following goal for the design: &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Entity Framework won’t define its own unique representation for the set of changes represented in an N-Tier application. Instead, it will provide basic building block APIs that will facilitate the use of a wide range of representations. &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;This has the desirable consequence that Entity Framework won’t impose a pattern for N-Tier. Both DTO-style and DataSet-like experiences can be built on top of a minimal set of building blocks APIs. It is up to the developer to select the pattern that better suits the application.&lt;/P&gt;
&lt;P&gt;Here is a first cut of the new methods that we are proposing to add to the ObjectContext. The new APIs will work with EntityObjects, IPOCO and POCO entities:&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;partial&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ObjectContext&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;{&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Apply property values to original state of the entity&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="entitySetName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;name of EntitySet of root&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="original"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;entity with original values&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ApplyOriginalValues(&lt;SPAN style="COLOR: blue"&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/SPAN&gt; entitySetName, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/SPAN&gt; original) { }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Changes the state of the entity and incident relationships &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="entity"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;entity to change state of&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="state"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;new state&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ChangeObjectState(&lt;SPAN style="COLOR: blue"&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/SPAN&gt; entity, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityState&lt;/SPAN&gt; state) { }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Changes state of relationship &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="source"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;source object of relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="target"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;target object of relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="relationshipName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;name of relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="sourceRole"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;role of source object&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="targetRole"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;role of target object&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt; &amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="state"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;new state&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ChangeRelationshipState(&lt;SPAN style="COLOR: blue"&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/SPAN&gt; source, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/SPAN&gt; target, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; relationshipName, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/SPAN&gt; sourceRole, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/SPAN&gt; targetRole, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;EntityState&lt;/SPAN&gt; state) { } &lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Changes state of relationship represented by navigation &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt; property&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="source"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;source object of relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="target"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;target object of relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="navigationProperty"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;navigation property&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="state"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;new state&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ChangeRelationshipState(&lt;SPAN style="COLOR: blue"&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/SPAN&gt; source, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/SPAN&gt; target, &lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string&lt;/SPAN&gt; navigationProperty, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityState&lt;/SPAN&gt; state) { }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Changes state of relationships represented by lambda &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt; expression&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;typeparam name="TSource"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;type of source entity&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="source"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;source entity of relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="target"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;target entity of relationship&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="selector"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;property selector expression&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="state"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;new state&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ChangeRelationshipState&amp;lt;TSource&amp;gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TSource source, &lt;SPAN style="COLOR: blue"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/SPAN&gt; target, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;TSource, &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt;&amp;gt; selector, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;EntityState&lt;/SPAN&gt; state) { }&lt;/SPAN&gt; &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&lt;SPAN&gt;}&lt;/SPAN&gt; &lt;/DIV&gt;
&lt;H3&gt;ApplyOriginalValues&lt;/H3&gt;
&lt;P&gt;Similar to the existing ApplyPropertyChanges, but this API keeps the tracked entity intact, only affecting the corresponding original values. This operation only works for entities in Modified, Unchanged or Deleted states. Added entities by definition don’t have original state.&lt;/P&gt;
&lt;H3&gt;ChangeObjectState&lt;/H3&gt;
&lt;P&gt;This method will transition the state of a tracked entity passed as argument, but will also have side-effects on incident relationships. In case the new state is modified, it will also mark all properties as modified, regardless of the original and current values.&lt;/P&gt;
&lt;H3&gt;ChangeRelationshipState&lt;/H3&gt;
&lt;P&gt;Similar to ChangeObjectState, but sets the relationship between two tracked entities to the provided state. Relationships cannot be in the modified state, but this method can be used to report which relationship should be added, deleted, or unchanged.&lt;/P&gt;
&lt;P&gt;The relationship doesn’t need to exist in the context, but the entities do. If the relationship doesn’t exist, it can be created in the new state. For instance, when this code is invoked, a new relationship can be created between customer1 and order1 in the added state:&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN&gt;context.ChangeRelationship( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; customer1, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order1, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c=&amp;gt;c.Orders, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityState&lt;/SPAN&gt;&lt;SPAN&gt;.Added);&lt;/SPAN&gt; &lt;/DIV&gt;
&lt;P&gt;The relationship is typically represented by the navigation property but the metadata names of the relationship and roles can also be used in a different overload. &lt;/P&gt;
&lt;H3&gt;Design notes&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;All parameters named “entity”, “source” and “target” accept either entities or EntityKeys.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;We could choose to deprecate the ApplyPropertyChanges API and replace it with ApplyCurrentValues, which is more consistent name-wise with the new ApplyOriginalValues method.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;For convenience, we should add similar APIs in other types like ObjectStateEntry, RelatedEnd and others as appropriate. For instance, the ObjectStateEntry will also have a ChangeState&amp;nbsp; API that will only take the target state parameter.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;We could choose to put ChangeObjectState() and the various ChangeRelationshipState() in ObjectStateManager rather than in ObjectContext, since this is a lower level API than everything else currently in the ObjectContext.&lt;/o:p&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H2&gt;Scenario tests&lt;/H2&gt;
&lt;P&gt;To get a sense of how the new API can be used, we have tried several different approaches and representations. We also have plans to release sample code that will show in more detail different ways to use the new API. In the meanwhile, here are a few simple cases.&lt;/P&gt;
&lt;H3&gt;General purpose Attach with state resolution delegate&lt;/H3&gt;
&lt;P&gt;In this scenario between a client and mid-tier, the intention is to allow a client to query for a Customer entity with the Customer’s Order entities. The client then makes a variety of changes to the Customer entity graph including modifying the Customer, and adding or removing Orders.&amp;nbsp; The client would like to send the updated Customer entity graph to the mid-tier so that it can be processed and persisted. &lt;/P&gt;
&lt;P&gt;This system will use a simple mechanism to help with change tracking on DTO entities. Each DTO will implement a small interface to help determine the state of the entity using three properties: IsNew, IsModified, and IsDeleted. In this example, original values are not tracked by the client.&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public interface&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IEntityWithChanges&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;{&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsNew { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsModified { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; IsDeleted { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;}&lt;/SPAN&gt; &lt;/DIV&gt;
&lt;P&gt;When the client makes changes to the Customer entity graph, the only requirement in this scenario is that when an entity changes, the appropriate property will return true to help determine the state of the entity. &lt;/P&gt;
&lt;P&gt;The mid-tier will expose a service method that implements the logic to update the Customer entity graph. Rather than traverse the Customer, her Orders and OrderLines looking for changes, the service method will use a convention based mechanism that knows how to deal with the IEntityWithChanges interfaces. In this scenario, this mechanism takes the form of an extension method to the ObjectContext that will attach an entity graph to the context, and use a delegate to map each entity that implements IEntityWithChanges to an EntityState so that it can be used with the new ChangeObjectState APIs. &lt;/P&gt;
&lt;P&gt;First we can define a method to map from an IEntityWithChanges to an EntityState:&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; A mapping from an IEntityWithChanges to an EntityState&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt; GetEntityState(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; entity)&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;{&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IEntityWithChanges&lt;/SPAN&gt; entityWithChanges = &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; entity &lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IEntityWithChanges&lt;/SPAN&gt;;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (entityWithChanges != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (entityWithChanges.IsNew)&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;.Added;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (entityWithChanges.IsModified)&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;.Modified;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (entityWithChanges.IsDeleted)&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;.Deleted;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;.Unchanged;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;}&lt;/SPAN&gt; &lt;/DIV&gt;
&lt;P&gt;Next we will define the extension method on an ObjectContext that can attach an entity graph and use a mapping delegate to determine the state of each entity in the graph.&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt; &lt;BR&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Attach a graph of entities using a supplied mapping function to &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; determine the entity's state. &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; In this example, the state of relationships between entities is &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; determined by the rules of ChangeObjectState: &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; - if one entity in the relationship is Added, the relationship is &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Added &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; - if an entity is Deleted or Detached, all incident relationships &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; are Deleted or Detached &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt; &lt;BR&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="entitySetName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;name of EntitySet of root&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt; &lt;BR&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="entityGraph"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;graph of entities to attach&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt; &lt;BR&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="entityStateMap"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;EntityState resolver&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Attach( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;this ObjectContext&lt;/SPAN&gt; context, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; entitySetName, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; entityGraph, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;&amp;gt; entityStateMap) &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;B&gt;&amp;nbsp;&lt;/B&gt;context.AttachTo(entitySetName, entityGraph); &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// Create a list of unique entities in the graph &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var&lt;/SPAN&gt; allEntities = &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .ObjectStateManager &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .GetObjectStateEntries(EntityState.Unchanged) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Where(entry =&amp;gt; !entry.IsRelationship) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Select(entry =&amp;gt; entry.Entity); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// Apply the entityStateMap to each entity &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; entity &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; allEntities) &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; context.ChangeObjectState(entity, entityStateMap(entity)); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;}&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt; &lt;/DIV&gt;
&lt;P&gt;Finally we can define our service method that can update a Customer entity graph using the mapping delegate and the Attach extension method.&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; A service method to update a Customer's entity graph which &lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; can include modifications to the Customer entity, &lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; new Orders, and removal of Orders&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="c"&amp;gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; UpdateCustomerOrder(&lt;SPAN style="COLOR: #2b91af"&gt;Customer&lt;/SPAN&gt; customer)&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;{&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;NorthwindEntities&lt;/SPAN&gt; context = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;NorthwindEntities&lt;/SPAN&gt;())&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// Call the Attach extenion method with the mapping delegate &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// that goes from IEntityWithChanges to EntityState&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.Attach(&lt;SPAN style="COLOR: #a31515"&gt;"Customers"&lt;/SPAN&gt;, customer, GetEntityState);&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.SaveChanges();&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&gt;}&lt;/SPAN&gt; &lt;/DIV&gt;
&lt;H3&gt;&lt;SPAN style="FONT-FAMILY: " color:="COLOR:" calibri?,?sans-serif?;="calibri?,?sans-serif?;" #1f497d?="#1f497d?"&gt;&lt;BR&gt;&lt;/SPAN&gt;ChangeOrder Service Operation&lt;/H3&gt;
&lt;P&gt;In this scenario, the mid-tier exposes a method to perform a very specific operation: changing the Customer that owns an Order. The client can set the Order’s Customer to a new Customer or to one that already exists in the store. In either case, the service method uses the old Customer so that it can remove the relationship between the Order and that Customer.&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt; &lt;BR&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; Updates an Order by changing the relationship between the Order &lt;BR&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt; and a Customer in this case &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt; &lt;BR&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="updatedOrder"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;order to update&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt; &lt;BR&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="oldCustomer"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;previous customer&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ChangeOrder(&lt;SPAN style="COLOR: #2b91af"&gt; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Order&lt;/SPAN&gt; updatedOrder, &lt;SPAN style="COLOR: #2b91af"&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Customer&lt;/SPAN&gt; oldCustomer) &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;NorthwindEntities&lt;/SPAN&gt; context = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;NorthwindEntities&lt;/SPAN&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; &lt;SPAN style="COLOR: green"&gt;// Tell the context about the entities to persist &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.AttachTo(&lt;SPAN style="COLOR: #a31515"&gt;"Orders"&lt;/SPAN&gt;, updatedOrder); &lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// Change the state of the new customer &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// In this example, this is done by the convention: &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// - Customer.CustomerID is null --&amp;gt; customer is 'Added' &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// - Customer.CustomerID is not null --&amp;gt; it already exists &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt;(updatedOrder.Customer.CustomerID == &lt;SPAN style="COLOR: #a31515"&gt;""&lt;/SPAN&gt;) &lt;BR&gt;&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; &lt;SPAN style="COLOR: green"&gt;// When state of customer changes to 'Added', state &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// of the relationship between updatedOrder and &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// pdatedOrder.Customer is also changed to 'Added' &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.ChangeObjectState( &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;&amp;nbsp; updatedOrder.Customer, &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;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;.Added); &lt;BR&gt;&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; &lt;SPAN style="COLOR: blue"&gt;else &lt;BR&gt;&lt;/SPAN&gt;&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; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (updatedOrder.Customer.CustomerID != &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;&amp;nbsp; oldCustomer.CustomerID) &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; { &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;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// only relationship needs to be marked as 'Added' &lt;BR&gt;&lt;/SPAN&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;&amp;nbsp; context.ChangeRelationshipState( &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updatedOrder, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updatedOrder.Customer, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o =&amp;gt; o.Customer, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;.Added); &lt;BR&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;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// Report removal of relationship between &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;&amp;nbsp; // pdatedOrder and oldCustomer&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;BR&gt;&lt;SPAN&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;&amp;nbsp; context.ChangeRelationshipState( &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updatedOrder, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oldCustomer, &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Customer", &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;EntityState&lt;/SPAN&gt;.Deleted);&lt;/SPAN&gt; &lt;BR&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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; } &lt;BR&gt;&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; &lt;SPAN style="COLOR: green"&gt;// Persist the changes to the store &lt;BR&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.SaveChanges(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;}&lt;/SPAN&gt; &lt;/DIV&gt;
&lt;P&gt;As is always the case, your feedback on this topic is welcome! &lt;/P&gt;
&lt;P&gt;Jeff Derstadt &lt;BR&gt;Jaroslaw Kowalski &lt;BR&gt;Diego Vega &lt;BR&gt;and The Object Services Team&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/EM&gt;&lt;/STRONG&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;FONT color=#4c6d7e&gt;&lt;STRONG&gt;&lt;EM&gt;this post&lt;/EM&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;STRONG&gt;&lt;EM&gt;.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9127479" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/POCO/default.aspx">POCO</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/ObjectServices/default.aspx">ObjectServices</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/N-Tier/default.aspx">N-Tier</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>Foreign Keys in the Conceptual and Object Models</title><link>http://blogs.msdn.com/efdesign/archive/2008/10/27/foreign-keys-in-the-conceptual-and-object-models.aspx</link><pubDate>Mon, 27 Oct 2008 19:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9018535</guid><dc:creator>efdesign</dc:creator><slash:comments>36</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/9018535.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=9018535</wfw:commentRss><description>&lt;P&gt;If you are reading this, you have probably heard by now about the so called impedance mismatch between the relational world and the object world – and there are a number of concepts in the relational database that don’t translate easily to corresponding concepts supported by the object oriented paradigm. One of these factors that is particularly interesting (and often controversial) is the concept of Foreign Keys and whether or not they belong in your conceptual/object model.&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;FKs are used to represent relationships in the database – but with objects, the natural way to represent relationships is through real references between objects. So as an object relational mapping platform, should a product support one or the other, or both?&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;I think most will agree that there is tremendous value in supporting relationships in the model as first class references between objects.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;What are some of the issues with supporting both foreign keys and references in the same model? We could take a real world example i.e. LINQ to SQL and its foreign key support to look at some of the benefits as well as the downsides to having foreign keys.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H3&gt;Foreign Key Support in LINQ to SQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/H3&gt;
&lt;P&gt;LINQ to SQL takes the simplistic approach of making foreign keys available to you as a scalar property in your entities. In essence, LINQ to SQL allows you to write code dealing with relationships like so:&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN class=type&gt;Product&lt;/SPAN&gt;&amp;nbsp;chai = db.Products.Where(p =&amp;gt; p.ProductName == &lt;SPAN class=stringliteral&gt;"Chai"&lt;/SPAN&gt;).Single(); &lt;BR&gt;chai.CategoryID = 1; &lt;BR&gt;db.SubmitChanges(); &lt;/DIV&gt;
&lt;P&gt;This is possible in LINQ to SQL mainly because foreign keys are somewhat central to the way relationships are implemented and supported. &lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;This particular example achieves something quite powerful, however - here you have essentially changed the category that the product Chai belonged to without ever having to query and materialize the new category that you associated Chai with.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;However, LINQ to SQL also allows you to do this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;DIV class=codeblock&gt;&lt;SPAN class=type&gt;Product&lt;/SPAN&gt; chai = db.Products.Where(p =&amp;gt; p.ProductName == &lt;SPAN class=stringliteral&gt;"Chai"&lt;/SPAN&gt;).Single(); &lt;BR&gt;&lt;SPAN class=type&gt;Category&lt;/SPAN&gt; beverages = db.Categories.Where(c =&amp;gt; c.CategoryName == &lt;SPAN class=stringliteral&gt;"Beverages"&lt;/SPAN&gt;).Single(); &lt;BR&gt;chai.Category = beverages; &lt;/DIV&gt;
&lt;P&gt;We have been considering for a while about whether or not we want to include support to allow you to expose foreign keys in the model. Let’s see what you gain / lose by having foreign keys in the model.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;One of the fundamental issues is that the simple foreign key concept that works so well in the relational model isn’t sufficient to represent relationships in the conceptual model. In the Entity Framework, a relationship is a first class concept that must be mapped to any set of columns in the database – and the important thing here is that these columns don’t have to represent relationships on the database by the means of FKs and constraints. Another point to note is that in the Entity Framework, relationships are always comprised of two ends, and are bi-directional unlike foreign keys.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;What does all of this do for the model?&amp;nbsp; This opens up possibilities, such as Referential Integrity constraints that are represented in the EDM even though they may not necessarily be present on the relational model in the store. Bi-directional nature of the relationships makes it possible for you to navigate in both directions along a relationship in a way that is generally not possible with a simple FK.&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;Foreign Keys are not without value, however. An interesting challenge for us is to figure out how to bring the best aspects of Foreign Keys into the Entity Framework without compromising the richness and flexibility that relationships bring to the table.&amp;nbsp; Let’s look at the upside and the downsides of plain relational foreign keys:&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H3&gt;Benefits of Foreign Keys&lt;o:p&gt;&lt;/o:p&gt;&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;Keeps it simple (for the simple cases)&amp;nbsp; and allows you to deal with relationship like you deal with them in the database&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;
&lt;LI&gt;Technically, you can update relationships without having both ends loaded/materialized. This is however in reality not always interesting since you will likely load both ends but this feature is definitely useful.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H3&gt;Disadvantages of Foreign Keys in the Model&lt;o:p&gt;&lt;/o:p&gt;&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;It is a part of the impedance mismatch problem.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;
&lt;LI&gt;It doesn’t allow the concepts that you would expect from relationships in objects (easily getting from one end to the other) for instance.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;
&lt;LI&gt;Having foreign keys as well as object references for relationship navigation presents the problem of two different artifacts representing relationships – this introduces complexity and now you have to make sure that you keep these two in sync.&lt;o:p&gt;&lt;/o:p&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;So where do you stand? Do you like foreign keys or do you think they are evil? Would you like to see Foreign Keys exposed in the model, and if they are available in your object model, would it be sufficient if they were read-only?&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P&gt;Let us know!&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Calibri size=3&gt;&lt;STRONG&gt;Faisal Mohamood&lt;/STRONG&gt;&amp;nbsp; &lt;BR&gt;Program Manager, &lt;BR&gt;Entity Framework Team&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Calibri size=3&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;&lt;FONT face=Calibri size=3&gt;this post&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9018535" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/ObjectServices/default.aspx">ObjectServices</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Linq+to+Sql/default.aspx">Linq to Sql</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>EDM and Store functions exposed in LINQ</title><link>http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx</link><pubDate>Wed, 08 Oct 2008 11:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8962709</guid><dc:creator>efdesign</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/8962709.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=8962709</wfw:commentRss><description>&lt;p&gt;In this post &lt;a href="http://blogs.msdn.com/meek" mce_href="http://blogs.msdn.com/meek"&gt;Colin Meek&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/diego" mce_href="http://blogs.msdn.com/diego"&gt;Diego Vega&lt;/a&gt; delve into some enhancements we are planning for LINQ to Entities, anyway over to them... &lt;/p&gt;  &lt;p&gt;Entity Framework v1 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. For some of those customers, having to resort to Entity SQL, or even to Entity SQL builder methods, feels awkward and reduces the appeal of Entity Framework. &lt;/p&gt;  &lt;p&gt;There are two things we want to do in order to address this in future versions:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Expand the range of patterns and standard BCL methods we recognize in LINQ expressions.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Provide an extensibility mechanism that people can use to map arbitrary CLR methods to appropriate server and EDM functions. &lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This blog post expands on the second approach: &lt;/p&gt;  &lt;p&gt;It is actually possible for us to improve our LINQ implementation so that all functions defined in the EDM and in the store, and even user defined functions, can be mapped to CLR methods with homologous signatures.&lt;/p&gt;  &lt;h3&gt;Design&lt;/h3&gt;  &lt;h4&gt;Problem space&lt;/h4&gt;  &lt;p&gt;There are multiple dimensions to the problem space we want to address:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Functions can be defined in either the conceptual or the storage space&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Functions can be defined in either the manifest, or just declared in the model&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Functions can be mapped to either static CLR methods or to instance methods on the ObjectContext&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;This feature specifically targets composable functions &lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;How it looks like: EdmFunctionAttribute &lt;/h4&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;div class="codeblock"&gt;&lt;span class="keyword"&gt;public &lt;/span&gt;EdmFunctionAttribute(&lt;span class="keyword"&gt;string &lt;/span&gt;namespaceName, &lt;span class="keyword"&gt;string &lt;/span&gt;functionName) &lt;/div&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;The following example could be product code or customer code applying the attribute on an extension method (it could be a regular static function) in order to map it to the standard deviation SQL Server function:&lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span&gt;&lt;span class="keyword"&gt;public static class &lt;/span&gt;&lt;span class="type"&gt;SqlFunctions &lt;/span&gt;      &lt;br&gt;{       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"SqlServer"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"stdev"&lt;/span&gt;)]       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public static double?&lt;/span&gt; StandardDeviation(&lt;span class="keyword"&gt;this &lt;/span&gt;IEnumerable&amp;lt;&lt;span class="keyword"&gt;int?&lt;/span&gt;&amp;gt; source)       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/span&gt;    &lt;br&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw &lt;/span&gt;EntityUtil.NotSupported(       &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; System.Data.Entity.Strings.ELinq_EdmFunctionDirectCall);       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }       &lt;br&gt;} &lt;/span&gt;&lt;/div&gt;  &lt;p&gt;Notice that while this method can’t be called directly it can be used in a query like this: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span&gt;&lt;span class="keyword"&gt;var &lt;/span&gt;query =&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;from&lt;/span&gt; p &lt;span class="keyword"&gt;in &lt;/span&gt;context.Products       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;where &lt;/span&gt;!p.Discontinued       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;group &lt;/span&gt;p &lt;span class="keyword"&gt;by &lt;/span&gt;p.Category &lt;span class="keyword"&gt;into &lt;/span&gt;g       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;select &lt;/span&gt;g.Select(each =&amp;gt; each.ReorderLevel).StandardDeviation(); &lt;/span&gt;&lt;/div&gt;  &lt;p&gt;The following example shows how the canonical DiffYear function is mapped: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;class&lt;/span&gt; &lt;span class="type"&gt;EntityFunctions        &lt;br&gt;&lt;/span&gt;{       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"EDM"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"DiffYears"&lt;/span&gt;)]       &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="type"&gt;Int32&lt;/span&gt;? DiffYears(&lt;span class="type"&gt;DateTime&lt;/span&gt;? arg1, &lt;span class="type"&gt;DateTime&lt;/span&gt;? arg2)       &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; &lt;span class="keyword"&gt;throw&lt;/span&gt; EntityUtil.NotSupported(System.Data.Entity.Strings.ELinq_EdmFunctionDirectCall);&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }       &lt;br&gt;} &lt;/span&gt;&lt;/div&gt;  &lt;p&gt;Usage is: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;var &lt;/span&gt;query =     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;from &lt;/span&gt;p &lt;span class="keyword"&gt;in &lt;/span&gt;context.Products     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;where &lt;/span&gt;&lt;span class="type"&gt;EntityFunctions&lt;/span&gt;.DiffYears(DateTime.Today, p.CreationDate) &amp;lt; 5     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;select &lt;/span&gt;p; &lt;/div&gt;  &lt;p&gt;The following example shows how a user defined function defined in SQL Server can be mapped: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;class&lt;/span&gt; &lt;span class="type"&gt;MyCustomFunctions      &lt;br&gt;&lt;/span&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"SqlServer"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"MyFunction"&lt;/span&gt;)]     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="type"&gt;Int32&lt;/span&gt;? MyFunction(&lt;span class="keyword"&gt;string&lt;/span&gt; myArg)     &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; &lt;span class="keyword"&gt;throw&lt;/span&gt; new &lt;span class="type"&gt;NotSupportedException&lt;/span&gt;(&lt;span class="stringliteral"&gt;"Direct calls not supported"&lt;/span&gt;);&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;} &lt;/div&gt;  &lt;h4&gt;Convention based function name &lt;/h4&gt;  &lt;p&gt;We can establish that by convention the name of the CLR function defines the value of the functionName parameter. That makes the functionName parameter in the EdmFunctionAttribute optional. &lt;/p&gt;  &lt;h4&gt;EdmFunctionNamespaceAttribute&lt;/h4&gt;  &lt;p&gt;To avoid having to always specify the namespaceName for each function, we define a new class-level attribute named &lt;b&gt;EdmFunctionNamespaceAttribute &lt;/b&gt;that would define the namespace mapping globally for a given class: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;public &lt;/span&gt;EdmFunctionNamespaceAttribute(&lt;span class="keyword"&gt;string &lt;/span&gt;namespaceName) &lt;/div&gt;  &lt;p&gt;Using EdmFunctionNamespaceAttribute and the convention based constructor: &lt;/p&gt;  &lt;div class="codeblock"&gt;[&lt;span class="type"&gt;EdmFunctionNamespace&lt;/span&gt;(&lt;span class="stringliteral"&gt;"EDM"&lt;/span&gt;)]     &lt;br&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;class&lt;/span&gt; &lt;span class="type"&gt;EdmMethods      &lt;br&gt;&lt;/span&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;]     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="type"&gt;Int32&lt;/span&gt;? DiffYears(&lt;span class="type"&gt;DateTime&lt;/span&gt;? arg1, &lt;span class="type"&gt;DateTime&lt;/span&gt;? arg2)     &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; &lt;span class="keyword"&gt;throw&lt;/span&gt; EntityUtil.NotSupported(     &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; System.Data.Entity.&lt;span class="type"&gt;Strings&lt;/span&gt;.ELinq_EdmFunctionDirectCall);&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;}&lt;/div&gt;  &lt;h4&gt;How it works &lt;/h4&gt;  &lt;p&gt;When a method with the EdmFunction attribute is detected within a LINQ query expression, its treatment is identical to that of a function within an Entity-SQL query. Overload resolution is performed with respect to the EDM types (not CLR types) of the function arguments. Ambiguous overloads, missing functions or lack of overloads result in an exception. In addition, the return type of the method must be validated. If the CLR return type does not have an implicit cast to the appropriate EDM type, the translation will fail. &lt;/p&gt;  &lt;p&gt;Instance methods on the ObjectContext will be supported as well. This allows the method to bootstrap itself and trigger direct evaluation, as in the following example (definition of the method and sample query): &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;public static class&lt;/span&gt; MyObjectContext : ObjectContext     &lt;br&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="comment"&gt;// Method definition&lt;/span&gt;     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"edm"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"floor"&lt;/span&gt;)]     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public &lt;/span&gt;&lt;span class="type"&gt;double&lt;/span&gt;&lt;span class="keyword"&gt;&lt;/span&gt;? Floor(&lt;span class="type"&gt;double&lt;/span&gt;? value)     &lt;br&gt;&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; return &lt;span class="keyword"&gt;this&lt;/span&gt;.QueryProvider.Execute&amp;lt;&lt;span class="type"&gt;double&lt;/span&gt;?&amp;gt;(&lt;span class="type"&gt;Expression&lt;/span&gt;.Call(     &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; &lt;span class="type"&gt;Expression&lt;/span&gt;.Constant(this),     &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; (&lt;span class="type"&gt;MethodInfo&lt;/span&gt;)&lt;span class="type"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod(),     &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; &lt;span class="type"&gt;Expression&lt;/span&gt;.Constant(value, &lt;span class="keyword"&gt;typeof&lt;/span&gt;(&lt;span class="type"&gt;double&lt;/span&gt;?))));     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;}     &lt;br&gt;    &lt;br&gt;…     &lt;br&gt;    &lt;br&gt;&lt;span class="comment"&gt;// evaluated in the store! &lt;/span&gt;    &lt;br&gt;context.Floor(0.1);     &lt;br&gt;&lt;/div&gt;  &lt;p&gt;Without the ObjectContext, the function cannot reach the store! To support this style of bootstrapping, the context needs to expose the LINQ query provider. For this reason, we now expose a “QueryProvider” property on the ObjectContext. This provider includes the necessary surface to construct or execute a query given a LINQ expression. &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;public class &lt;/span&gt;&lt;span class="type"&gt;ObjectContext &lt;/span&gt;    &lt;br&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public &lt;/span&gt;&lt;span class="type"&gt;IQueryProvider&lt;/span&gt; QueryProvider { &lt;span class="keyword"&gt;get&lt;/span&gt;; }     &lt;br&gt;} &lt;/div&gt;  &lt;p&gt;If such a method is encountered inline in another query, then we must validate that the instance argument (MethodCallExpression.Object) is the correct context, but the instance is otherwise ignored: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="comment"&gt;// positive &lt;/span&gt;    &lt;br&gt;&lt;span class="keyword"&gt;var &lt;/span&gt;q1 = &lt;span class="keyword"&gt;from &lt;/span&gt;p &lt;span class="keyword"&gt;in &lt;/span&gt;context.Products &lt;span class="keyword"&gt;select &lt;/span&gt;context.Floor(p.Price);     &lt;br&gt;    &lt;br&gt;&lt;span class="comment"&gt;// negative&lt;/span&gt;     &lt;br&gt;&lt;span class="keyword"&gt;var &lt;/span&gt;q2 = &lt;span class="keyword"&gt;from &lt;/span&gt;p &lt;span class="keyword"&gt;in &lt;/span&gt;context.Products &lt;span class="keyword"&gt;select &lt;/span&gt;context2.Floor(p.Price); &lt;/div&gt;  &lt;p&gt;A function proxy can sometimes bootstrap itself without an explicit context, e.g. when an input argument is itself an IQueryable: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;public static class &lt;/span&gt;&lt;span class="type"&gt;SqlFunctions &lt;/span&gt;    &lt;br&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"SqlServer"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"stdev"&lt;/span&gt;)]     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public static&lt;/span&gt; &lt;span class="keyword"&gt;double&lt;/span&gt;? StandardDeviation(&lt;span class="keyword"&gt;this&lt;/span&gt; &lt;span class="type"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;?&amp;gt; source)     &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; &lt;span class="keyword"&gt;return&lt;/span&gt; source.Provider.Execute&amp;lt;&lt;span class="keyword"&gt;double&lt;/span&gt;?&amp;gt;(&lt;span class="type"&gt;Expression&lt;/span&gt;.Call(     &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; (&lt;span class="type"&gt;MethodInfo&lt;/span&gt;)&lt;span class="type"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod(),     &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; &lt;span class="type"&gt;Expression&lt;/span&gt;.Constant(source)));     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;} &lt;/div&gt;  &lt;h4&gt;Nullability considerations &lt;/h4&gt;  &lt;p&gt;Particularly for functions taking collections, we will need to provide overloads for nullable and non-nullable elements. We don’t want to require awkward constructions like: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;var &lt;/span&gt;query = (&lt;span class="keyword"&gt;from &lt;/span&gt;p &lt;span class="keyword"&gt;in &lt;/span&gt;products &lt;span class="keyword"&gt;select &lt;/span&gt;(&lt;span class="keyword"&gt;int&lt;/span&gt;?)p.ReorderLevel).StandardDeviation(); &lt;/div&gt;  &lt;h4&gt;Tool for Generating the Functions &lt;/h4&gt;  &lt;p&gt;We created a simple internal tool that generates the classes that represent all the EDM canonical function and the SQL Server store functions. The tool will take the function definitions from Metadata and generate the appropriate function stubs/implementations. &lt;/p&gt;  &lt;p&gt;The tool will be outside the product and will be run on demand. We expect to make a version of this tool available for provider writers together with the provider samples. &lt;/p&gt;  &lt;h4&gt;Naming &lt;/h4&gt;  &lt;p&gt;The methods will be in the following classes: &lt;/p&gt;  &lt;table class="ms-column4-main"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td class="ms-column4-tl"&gt;&lt;b&gt;Namespace&lt;/b&gt; &lt;/td&gt;        &lt;td class="ms-column4-tl"&gt;&lt;b&gt;Class name&lt;/b&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td class="ms-column4-left"&gt;         &lt;br&gt;System.Data.Objects           &lt;br&gt;&lt;/td&gt;        &lt;td class="ms-column4-left"&gt;         &lt;br&gt;EntityFunctions &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td class="ms-column4-left"&gt;         &lt;br&gt;System.Data.Objects.SqlClient           &lt;br&gt;&lt;/td&gt;        &lt;td class="ms-column4-left"&gt;         &lt;br&gt;SqlFunctions &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;i&gt;Note: The equivalent class in LINQ to SQL is System.Data.Linq.SqlClient.SqlMethods. &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;The method names will correspond to the name of the EDM/SQL function they represent. The argument names will correspond to the argument names of the EDM/SQL functions as retrieved by the metadata. &lt;/p&gt;  &lt;p&gt;The recommendation for provider writers will be to include a similar static class in a namespace of the following form: &lt;/p&gt;  &lt;p&gt;&lt;i&gt;System.Data.Objects.[Standard provider namespace].[Standard provider prefix]Functions &lt;/i&gt;&lt;/p&gt;  &lt;h4&gt;Overloads and Implementation &lt;/h4&gt;  &lt;h5&gt;Non-aggregate Functions &lt;/h5&gt;  &lt;p&gt;For each non-aggregate function we create an overload with all inputs type as nullable of the CLR equivalent of their EDM primitive type, and the return type nullable of the CLR equivalent of their EDM primitive type.&lt;/p&gt;  &lt;p&gt;The implementation of the functions (what gets executed if the function is invoked outside an expression tree) will be to throw a NotSupportedException. &lt;/p&gt;  &lt;p&gt;Example: &lt;/p&gt;  &lt;div class="codeblock"&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;class&lt;/span&gt; &lt;span class="type"&gt;EntityFunctions      &lt;br&gt;&lt;/span&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"EDM"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"DiffYears"&lt;/span&gt;)]     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="type"&gt;Int32&lt;/span&gt;? DiffYears(&lt;span class="type"&gt;DateTime&lt;/span&gt;? arg1, &lt;span class="type"&gt;DateTime&lt;/span&gt;? arg2)     &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; &lt;span class="keyword"&gt;throw&lt;/span&gt; &lt;span class="type"&gt;EntityUtil&lt;/span&gt;.NotSupported(System.Data.Entity.&lt;span class="type"&gt;Strings&lt;/span&gt;.ELinq_EdmFunctionDirectCall);&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;} &lt;span class="keyword"&gt;     &lt;br&gt;      &lt;br&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;class&lt;/span&gt; &lt;span class="type"&gt;SqlFunctions      &lt;br&gt;&lt;/span&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"SqlServer"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"DiffYears"&lt;/span&gt;)]     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="type"&gt;Int32&lt;/span&gt;? DiffYears(&lt;span class="type"&gt;DateTime&lt;/span&gt;? arg1, &lt;span class="type"&gt;DateTime&lt;/span&gt;? arg2)     &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; &lt;span class="keyword"&gt;throw&lt;/span&gt; &lt;span class="type"&gt;EntityUtil&lt;/span&gt;.NotSupported(System.Data.Entity.&lt;span class="type"&gt;Strings&lt;/span&gt;.ELinq_EdmFunctionDirectCall);&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;} &lt;/div&gt;  &lt;h5&gt;Aggregate Functions &lt;/h5&gt;  &lt;p&gt;For each aggregate function we will provide two overloads, one with IEnumerable&amp;lt;Nullable&amp;lt;T&amp;gt;&amp;gt; and another one with IEnumerable&amp;lt;T&amp;gt;, where T is the CLR equivalent of the EDM primitive type of the input. The implementations of these will check whether the input is IQueryable in which case it will implement the self-bootstrapping. &lt;/p&gt;  &lt;p&gt;Example: &lt;/p&gt;  &lt;div class="codeblock"&gt;[&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"EDM"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"VARP"&lt;/span&gt;)]     &lt;br&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;double&lt;/span&gt;? VarP(&lt;span class="type"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;&amp;gt; arg1)     &lt;br&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="type"&gt;ObjectQuery&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;&amp;gt; objectQuerySource = source &lt;span class="keyword"&gt;as&lt;/span&gt; &lt;span class="type"&gt;ObjectQuery&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;&amp;gt;;     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;if&lt;/span&gt; (objectQuerySource != &lt;span class="keyword"&gt;null&lt;/span&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; &lt;span class="keyword"&gt;return&lt;/span&gt; ((&lt;span class="type"&gt;IQueryable&lt;/span&gt;)objectQuerySource).Provider.Execute&amp;lt;&lt;span class="keyword"&gt;double&lt;/span&gt;?&amp;gt;(&lt;span class="type"&gt;Expression&lt;/span&gt;.Call(     &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; (&lt;span class="type"&gt;MethodInfo&lt;/span&gt;)&lt;span class="type"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod(),     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="type"&gt;Expression&lt;/span&gt;.Constant(source)));     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;throw&lt;/span&gt; &lt;span class="type"&gt;EntityUtil&lt;/span&gt;.NotSupported(System.Data.Entity.&lt;span class="type"&gt;Strings&lt;/span&gt;.ELinq_EdmFunctionDirectCall);&amp;nbsp; &lt;br&gt;}     &lt;br&gt;    &lt;br&gt;[&lt;span class="type"&gt;EdmFunction&lt;/span&gt;(&lt;span class="stringliteral"&gt;"EDM"&lt;/span&gt;, &lt;span class="stringliteral"&gt;"VARP"&lt;/span&gt;)]     &lt;br&gt;&lt;span class="keyword"&gt;public&lt;/span&gt; &lt;span class="keyword"&gt;static&lt;/span&gt; &lt;span class="keyword"&gt;double&lt;/span&gt;? VarP(&lt;span class="type"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;int&lt;/span&gt;?&amp;gt; arg1)     &lt;br&gt;{     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="type"&gt;ObjectQuery&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;int?&lt;/span&gt;&amp;gt; objectQuerySource = source &lt;span class="keyword"&gt;as&lt;/span&gt; &lt;span class="type"&gt;ObjectQuery&lt;/span&gt;&amp;lt;&lt;span class="keyword"&gt;int?&lt;/span&gt;&amp;gt;;     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;if&lt;/span&gt; (objectQuerySource != &lt;span class="keyword"&gt;null&lt;/span&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; &lt;span class="keyword"&gt;return&lt;/span&gt; ((&lt;span class="type"&gt;IQueryable&lt;/span&gt;)objectQuerySource).Provider.Execute&amp;lt;&lt;span class="keyword"&gt;double&lt;/span&gt;?&amp;gt;(&lt;span class="type"&gt;Expression&lt;/span&gt;.Call(     &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; (&lt;span class="type"&gt;MethodInfo&lt;/span&gt;)&lt;span class="type"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod(),     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="type"&gt;Expression&lt;/span&gt;.Constant(source)));     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }     &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="keyword"&gt;throw&lt;/span&gt; &lt;span class="type"&gt;EntityUtil&lt;/span&gt;.NotSupported(System.Data.Entity.&lt;span class="type"&gt;Strings&lt;/span&gt;.ELinq_EdmFunctionDirectCall);&amp;nbsp; &lt;br&gt;}     &lt;br&gt;&lt;/div&gt;  &lt;p&gt;The Entity Framework team would love to hear your comments.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/alexj" mce_href="http://blogs.msdn.com/alexj"&gt;Alex James&lt;/a&gt;&lt;/b&gt;&amp;nbsp; &lt;br&gt;Program Manager,     &lt;br&gt;Entity Framework Team&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;i&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;a href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;this post&lt;/a&gt;.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8962709" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Linq+to+Entities/default.aspx">Linq to Entities</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>Model First</title><link>http://blogs.msdn.com/efdesign/archive/2008/09/10/model-first.aspx</link><pubDate>Wed, 10 Sep 2008 23:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8942000</guid><dc:creator>efdesign</dc:creator><slash:comments>42</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/8942000.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=8942000</wfw:commentRss><description>&lt;p&gt;One of the most painful omissions from the Entity Framework V1 was Model First, which basically means creating a conceptual 'model first' and then deriving a storage model, database and mappings from that. &lt;/p&gt;
&lt;p&gt;People ask for this scenario all the time in the forums.&lt;/p&gt;
&lt;p&gt;Well Noam, a Program Manager on the Entity Framework Tools team, outlines what we are considering:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Generating Databases from Models&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;The next release of the Entity Framework will include the ability to generate database schemas from your model. The main entry point into this feature is via the Designer context menu, to which we will add a new option called “Create Database from Model”.&lt;/p&gt;
&lt;p&gt;(Note: User interface elements in this walkthrough are not final user interfaces, as the design is still under review, so please provide feedback...)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/image_2.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/image_thumb.png" style="border: 0px none ;" alt="image" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/image_thumb.png" width="315" border="0" height="395"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Selecting this option will bring up the following warning:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001_thumb.jpg" style="border: 0px none ;" alt="clip_image001" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001_thumb.jpg" width="428" border="0" height="209"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We would like users to understand that this feature will regenerate all SSDL and all MSL from scratch.&lt;/p&gt;
&lt;p&gt;If you have started from an empty model, you will be asked to specify the target database. This screen is identical to the one shown when reverse engineering a model from a database. The implication here is that you will need an available server and database, which the system will use to determine what “flavor” of DDL to generate.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image002_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image002_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image002_thumb.jpg" style="border: 0px none ;" alt="clip_image002" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image002_thumb.jpg" width="314" border="0" height="274"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once you have selected the target database, you will be presented with a summary screen which will provide a preview of the DDL that will be generated, as well as a tree-view of the objects.&lt;/p&gt;
&lt;p&gt;The tree view:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image003_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image003_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image003_thumb.jpg" style="border: 0px none ;" alt="clip_image003" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image003_thumb.jpg" width="314" border="0" height="274"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The DDL view:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image004_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image004_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image004_thumb.jpg" style="border: 0px none ;" alt="clip_image004" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image004_thumb.jpg" width="314" border="0" height="274"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The DDL in the above screenshot is there merely as a graphic used to show how what the window will look like and is not intended to be representative of the DDL that will be generated by the system when you are actually creating your database (more about this soon). The DDL will however&amp;nbsp;be read-only: Since it is generated by a template, editing of the results should either be done in the template, or in a separate DDL file which will not get regenerated.&lt;/p&gt;
&lt;p&gt;Two options will be available:&lt;/p&gt;
&lt;p&gt;- Save the DDL (off by default). This option will add the DDL as a dependent file under your EDMX file.&lt;/p&gt;
&lt;p&gt;- Deploy the DDL (on by default). This option will deploy the DDL to the specified target database.&lt;/p&gt;
&lt;p&gt;The generated DDL will not migrate data or schema - by default your database will be recreated from scratch.&lt;/p&gt;
&lt;p&gt;Out of the box, we will support the Table-per-Type mapping strategy, meaning that we will create a table for each of your types and subtypes. For example, for a model like this…&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image006_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image006_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image006_thumb.jpg" style="border: 0px none ;" alt="clip_image006" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image006_thumb.jpg" width="256" border="0" height="192"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;…the following schema will be generated:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image008_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image008_2.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image008_thumb.jpg" style="border: 0px none ;" alt="clip_image008" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image008_thumb.jpg" width="299" border="0" height="214"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Of interest here is that PK-to-PK constraint between the Customer and Persons table. This helps enforce the inheritance relationship and the creation of foreign key columns to represent the various associations. In addition, the engine will create clustered keys on primary keys, and indexes on foreign keys that represent associations.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Under the Hood&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;The model first process is implemented using a Windows Workflow Foundation workflow that looks like this:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001%5B5%5D.jpg" mce_href="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001%5B5%5D.jpg"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001%5B5%5D_thumb.jpg" style="border: 0px none ;" alt="clip_image001[5]" mce_src="http://blogs.msdn.com/blogfiles/efdesign/WindowsLiveWriter/ModelFirst_C141/clip_image001%5B5%5D_thumb.jpg" width="468" border="0" height="666"&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Here is what the stages do:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Stage&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Purpose&lt;/b&gt;&lt;/p&gt;
&lt;table style="border-collapse: collapse;" class="MsoNormalTable" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;tbody&gt;
&lt;tr style=""&gt;
&lt;td style="border: 1pt solid rgb(165, 165, 165); padding: 2.15pt 5.75pt; background: rgb(0, 112, 192) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 73.25pt;" width="98" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 8pt; color: white;"&gt;Stage&lt;/span&gt;&lt;span style="color: white;"&gt; 
&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: solid solid solid none; border-color: rgb(165, 165, 165) rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 2.15pt 5.75pt; background: rgb(0, 112, 192) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 441.55pt;" width="589" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 8pt; color: white;"&gt;Purpose&lt;/span&gt;&lt;span style="color: white;"&gt; 
&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 73.25pt;" width="98" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8pt;"&gt;CSDLtoSSDL&lt;/span&gt; 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 441.55pt;" width="589" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Creates the mappings (MSL) and database store model (SSDL) in the EDMX file. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 73.25pt;" width="98" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8pt;"&gt;SSDLtoDBSchema&lt;/span&gt; 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 441.55pt;" width="589" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Converts the SSDL to the format used by the Microsoft.Data.Schema APIs. This format is used as a “universal” database description format and includes physical information not present in the Entity Frameworks store model, such as indexes. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 73.25pt;" width="98" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8pt;"&gt;GenerateDDL&lt;/span&gt; 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 441.55pt;" width="589" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Uses the Microsoft.Data.Schema APIs to convert the universal format to store-specific DDL. In this release, we will support a minimum of SQL 2005 and SQL 2008. A provider model is in place, however, and we hope to add support for additional databases. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 73.25pt;" width="98" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8pt;"&gt;SuspendToConfirm&lt;/span&gt; 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 441.55pt;" width="589" valign="top"&gt;
&lt;p class="MsoNormal"&gt;This activity pauses the workflow to allow the wizard to display the DDL. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 73.25pt;" width="98" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8pt;"&gt;DeployToDatabase&lt;/span&gt; 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 441.55pt;" width="589" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Deploys the DDL to the target database. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 73.25pt;" width="98" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 8pt;"&gt;OutputDDL&lt;/span&gt; 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 441.55pt;" width="589" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Writes the DDL to the file system. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;These stages are expressed in a XAML file which will be placed underneath your EDMX, to allow for customization: You can add your own steps or replace ones we have created with steps that you write.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Templates&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Several of the steps above make use of templates to provide an additional point of control for users, and this is where we expect most of the customization to happen. These templates use the T4 &lt;a href="http://msdn.microsoft.com/en-us/library/bb126445.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb126445.aspx"&gt;Engine that is included in Visual Studio&lt;/a&gt;. We are currently working on making these templates as simple as possible by providing a set of supporting APIs that provide metadata collections that are designed for artifact generation – for example, a collection of all inherited properties for a type, or a collection of both inherited and defined properties. There are three templates:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Template&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Purpose&lt;/b&gt;&lt;/p&gt;
&lt;table style="border-collapse: collapse;" class="MsoNormalTable" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;tbody&gt;
&lt;tr style=""&gt;
&lt;td style="border: 1pt solid rgb(165, 165, 165); padding: 2.15pt 5.75pt; background: rgb(0, 112, 192) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 107.6pt;" width="143" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 8pt; color: white;"&gt;Template&lt;/span&gt;&lt;span style="color: white;"&gt; 
&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: solid solid solid none; border-color: rgb(165, 165, 165) rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 2.15pt 5.75pt; background: rgb(0, 112, 192) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 407.95pt;" width="544" valign="top"&gt;
&lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 8pt; color: white;"&gt;Purpose&lt;/span&gt;&lt;span style="color: white;"&gt; 
&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 107.6pt;" width="143" valign="top"&gt;
&lt;p class="MsoNormal"&gt;CSDL to SSDL 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 407.95pt;" width="544" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Creates the SSDL for the target database. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 107.6pt;" width="143" valign="top"&gt;
&lt;p class="MsoNormal"&gt;CSDL to MSL 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 407.95pt;" width="544" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Creates the MSL for mapping the CSDL to the generated SSDL. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=""&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165); border-width: medium 1pt 1pt; padding: 2.15pt 5.75pt; width: 107.6pt;" width="143" valign="top"&gt;
&lt;p class="MsoNormal"&gt;SSDL to DBSchema 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(165, 165, 165) rgb(165, 165, 165) -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 2.15pt 5.75pt; width: 407.95pt;" width="544" valign="top"&gt;
&lt;p class="MsoNormal"&gt;Creates the physical database description, including elements such as foreign keys and indexes. 
&lt;/p&gt;&lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;So, for example, if you need all table names to start with “_tbl”, you would modify the SSDL generation template to give all tables the appropriate name, and also modify the MSL template to provide the appropriate mappings. The DBSchema template will not need to be modified as it will automatically pick up the changes made to the SSDL which is its input.&lt;/p&gt;
&lt;p&gt;As another example, if you wish to change the mapping strategy from Table-per-Type to Table-per-Hierarchy, you would need to change this same pair of templates.&lt;/p&gt;
&lt;p&gt;Finally, if you needed to support a database for which no Microsoft.Data.Schema provider is available, you could replace the GenerateDDL step with your own template-driven activity which could them transform the schema “manually” to your store’s DDL format.&lt;/p&gt;
&lt;p&gt;We hope this gives you enough information to understand the design and intent of this feature.&lt;/p&gt;
&lt;p&gt;We&amp;nbsp;would love to hear your comments.&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, &lt;br&gt;Entity Framework Team&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;this post&lt;/a&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;. &lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8942000" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Metadata/default.aspx">Metadata</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Model+First/default.aspx">Model First</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>Structural Annotations - One Pager</title><link>http://blogs.msdn.com/efdesign/archive/2008/08/12/structural-annotations-one-pager.aspx</link><pubDate>Tue, 12 Aug 2008 22:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8853248</guid><dc:creator>efdesign</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/8853248.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=8853248</wfw:commentRss><description>&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;In V1 of the Entity Framework &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;it is possible to annotate a schema using attributes declared in another XSD. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;However XML attributes are a very limited form of annotation. It would be better if we could annotate using full elements.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;This is what we are calling Structural Annotations. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;This feature will allow both customers and partners like Reporting Services to modify the model so that it includes information important to them which can’t be captured in vanilla EDM format.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="border-style: solid none none; border-color: rgb(51, 51, 153) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 1pt 0in 0in;"&gt;
&lt;h3&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;1&lt;a class="" title="_Toc205113853" name="_Toc205113853"&gt;&lt;/a&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;EDM extensions &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;While it should be possible to annotate any level in the XML hierarchy, there are however some restrictions.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;The general rule is you can annotation any CSDL / SSDL element that has a corresponding&amp;nbsp; &lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%; font-family: 'Courier New';"&gt;MetadataItem&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;which&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt; in practice means everything except &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Using&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt;&lt;/span&gt;, &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Schema&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt;&lt;/span&gt;, &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Key&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;and &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;PropertyRef&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;elements.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;These annotations should be named, so that they can be accessed using the same API as today. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;i.e. something like this: &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EntityType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;Content&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Key&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;PropertyRef&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;ID&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Key&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Property&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;ID&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Guid&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;Nullable&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;false&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Property&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;HTML&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;String&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;Nullable&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;false&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;MaxLength&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Max&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;Unicode&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;true&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;FixedLength&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;false&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;CLR:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Attribute&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;TypeName&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;System.Runtime.Serialization.DataContract&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;CLR:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Attribute&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;TypeName&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;MyNamespace.MyAttribute&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;RS:Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;RS:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;ACE&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Principal&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;S-0-123-1321&lt;/span&gt;" &lt;span style="color: red;"&gt;Rights&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;+R+W&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;RS:&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ACE&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;Principal&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;S-0-123-2321&lt;/span&gt;" &lt;span style="color: red;"&gt;Rights&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;-R-W&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;RS:Security&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EntityType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;1.1&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Key points to notice:&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;In &lt;/span&gt;&lt;/span&gt;the above example both the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR&lt;/span&gt; and &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;RS&lt;/span&gt; namespaces must have been declared somewhere. Probably at the root of the CSDL somewhere, i.e. something like this: &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Schema&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;xmlns:RS&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;http://schemas.microsoft.com/RS/2006&lt;/span&gt;"&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;xmlns:CLR&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://schemas.microsoft.com/net/3.5" mce_href="http://schemas.microsoft.com/net/3.5"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;http://schemas.microsoft.com/net/3.5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;…&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Alternatively the namespace could be in lined in the annotation: &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;xmlns&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;http://schemas.microsoft.com/RS/2006&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;… &lt;br&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;In both cases the unique identity of the annotation is in the form &lt;i style=""&gt;{namespace}:{elementname}&lt;/i&gt;. So for the RS Security annotation example, irrespective of how the RS namespace is introduced the identity would be: &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://schemas.microsoft.com/RS/2006:Security" mce_href="http://schemas.microsoft.com/RS/2006:Security"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;http://schemas.microsoft.com/RS/2006:Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Structural annotations should always follow all other sub-elements i.e. when structurally annotating an &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EntityType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;element the annotation element should follow all &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Key&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Property&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt;&lt;/span&gt; and &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;NavigationProperty&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;elements. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Attribute based annotations (as supported in V1 and used for things like CodeGen) are scoped to the same annotation identity namespace. Hence care should be taken to verify that annotations using either approach don’t have colliding identities. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;It should be possible to have more than one named “Structural Annotation” per CSDL (or SSDL) element. Indeed element names can collide so long as the combination of Namespace + Element Name is unique for a particular element (or more specifically each &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;MetadataItem&lt;/span&gt;). This means for instance you can’t have two &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;RS:Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;elements under any one &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;MetadataItem&lt;/span&gt;. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;1.2&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Positive and Negative Cases:&lt;/h4&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;This: &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EntityType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;Content&lt;/span&gt;" &lt;span style="color: red;"&gt;CLR:Attribute&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Blah&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;CLR:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Attribute&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;TypeName&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;System.Runtime.Serialization.DataContract&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;…would be invalid, because of the identity collision, likewise this would also be invalid: &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EntityType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;Content&lt;/span&gt;" &lt;span style="color: red;"&gt;My:Attribute&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Blah&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;CLR:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Attribute&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;TypeName&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;System.Runtime.Serialization.DataContract&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;CLR:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Attribute&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;TypeName&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;MyNamespace.MyAttribute&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;where-as this is fine: &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EntityType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Name&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;Content&lt;/span&gt;" &lt;span style="color: red;"&gt;My:Attribute&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;Blah&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;CLR:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Attribute&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;TypeName&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;System.Runtime.Serialization.DataContract&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;CLR:Attributes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;RS:Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;RS:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;ACE&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Principal&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;span style="color: blue;"&gt;S-0-123-1321&lt;/span&gt;" &lt;span style="color: red;"&gt;Rights&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;+R+W&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;RS:&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ACE&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;Principal&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;S-0-123-2321&lt;/span&gt;" &lt;span style="color: red;"&gt;Rights&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;-R-W&lt;/span&gt;"&lt;span style="color: blue;"&gt;/&amp;gt; &lt;br&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;RS:Security&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;… since all the above annotations have unique identities. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;1.3&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;What can an &amp;lt;Annotation&amp;gt; contain&lt;/span&gt;?&lt;/h4&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;A structural annotation is simply an XML element. As such it can be considered a root of an XML document that can contain any valid XML structures. These structures are simply ignored by the Entity Framework and Metadata APIs. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;1.4&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;What elements can be annotated&lt;/span&gt;?&lt;/h4&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;If an element in the CSDL or SSDL has a corresponding &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;MetadataItem&lt;/span&gt; in the Metadata API that element should support structural annotations. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Since &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Using&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt;&lt;/span&gt;, &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Schema&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt;&lt;/span&gt;, &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Key&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;and &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(163, 21, 21); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;PropertyRef&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;gt; &lt;/span&gt;elements have no corresponding &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;MetadataItem&lt;/span&gt;(s) they don’t support structural annotations. 
&lt;p mce_keep="true"&gt;&lt;/p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Notice while &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;TypeUsage&lt;/span&gt;(s) have no CSDL representation today,they are &lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%; font-family: 'Courier New';"&gt;MetadataItem&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;(s) so they could in theory be annotated in the future. For example if a public mutable metadata API is produced.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="border-style: solid none none; border-color: rgb(51, 51, 153) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 1pt 0in 0in;"&gt;
&lt;h3&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&lt;b&gt;&lt;font face="Verdana" size="4"&gt;2&lt;/font&gt;&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Metadata API Changes:&lt;/h3&gt;&lt;/div&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;In this example we are using the Entity Frameworks Metadata API to get the &lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); font-family: 'Courier New';"&gt;EdmType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;for an &lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); font-family: 'Courier New';"&gt;EntityType &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;called Content. From that we then get the &lt;span style="color: rgb(43, 145, 175);"&gt;MetadataProperty&lt;/span&gt; called &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://schemas.microsoft.com/RS/2006:Security" mce_href="http://schemas.microsoft.com/RS/2006:Security"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;http://schemas.microsoft.com/RS/2006:Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175);" yes?="" mso-no-proof:="" new?;="" courier=""&gt;EdmType&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; contentType = metadataWorkspace.GetEdmType(&lt;span style="color: red;"&gt;“MyNamespace.Content”&lt;/span&gt;); &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;if&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; (contentType.MetadataProperties.Contains( &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://schemas.microsoft.com/RS/2006:Security" mce_href="http://schemas.microsoft.com/RS/2006:Security"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;http://schemas.microsoft.com/RS/2006:Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;) &lt;br&gt;{ &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;MetadataProperty&lt;/span&gt; annotationProperty = contentType.MetadataProperties[ &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://schemas.microsoft.com/RS/2006:Security" mce_href="http://schemas.microsoft.com/RS/2006:Security"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;http://schemas.microsoft.com/RS/2006:Security&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: red;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;];&amp;nbsp;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue;"&gt;object&lt;/span&gt; annotationValue = annotationProperty.Value; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: green;"&gt;//Do something... &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;}&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Notice that the way you access structural annotations is the same as the way you access attribute annotations, i.e. by name/identity, in the MetadataProperties collection. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;This of course means that their names can’t collide, name collisions should be picked up when metadata is loaded from persistent formats (like CSDL) or when annotations are created by hand in the any future mutable metadata API. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;2.1&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;MetadataProperty TypeUsage&lt;/h4&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;When creating a MetadataProperty to hold the XElement for the structural annotation, we need to assign a TypeUsage too. For V1 style attribute annotations, the &lt;a style=""&gt;TypeUsage we chose was based on Edm.String. Ideally we should use Edm.XML etc, but since this is not currently available, we will use Edm.String in the meantime. We have filled a bug to change this if/when &lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span class="MsoCommentReference"&gt;&lt;span style="font-size: 8pt; line-height: 115%;"&gt;&lt;a href="http://sharepoint/#_msocom_1" language="JavaScript" class="" id="_anchor_1" title="_msoanchor_1" name="_msoanchor_1" mce_href="http://sharepoint/#_msocom_1"&gt;[j1]&lt;/a&gt;&lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;XML becomes an EDM type. &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="border-style: solid none none; border-color: rgb(51, 51, 153) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 1pt 0in 0in;"&gt;
&lt;h3&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&lt;b&gt;&lt;font face="Verdana" size="4"&gt;3&lt;/font&gt;&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;What is the MetadataProperty.Value?&lt;/h3&gt;&lt;/div&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;The Value of the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;MetadataProperty&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;will be a &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;XElement&lt;/span&gt; for structural annotations originating from CSDL. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;So if you know that the annotation is a structural annotation you can access it like this: &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;MetadataProperty&lt;/span&gt; annotationProperty = &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style=""&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;contentType.MetadataProperties[&lt;span style="color: rgb(163, 21, 21);"&gt;"CLR:Attributes"&lt;/span&gt;]; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;XElement&lt;/span&gt; myAnnotation = annotationProperty.Value &lt;span style="color: blue;"&gt;as&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;XElement&lt;/span&gt;; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;3.1&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;XElement is rooted at the &amp;lt;Annotation&amp;gt; element&lt;/h4&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;The &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;XElement&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;returned will be the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;XElement&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;containing everything including the structural annotation itself. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;3.2&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;XElement is mutable&lt;/h4&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;There is nothing to stop the consumer of the Metadata API from modifying the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;XElement&lt;/span&gt; since it is simply a reference, to an instance of a type the Entity Framework doesn’t control. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;We could address this by cloning on access to make things a little safer. But this negatively affects the mainline scenario, namely where a customer uses annotations purely for read, and is therefore not required. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;The important thing to understand is that should a user modify the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;XElement&lt;/span&gt; all bets are off. We should provide guidance both via API hints: &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0pt; line-height: normal;"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;summary&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; .... &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;remarks&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; Should this return a reference type like an XElement, you should consider &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; this immutable, no guarantees are made about behavior if this reference &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; type is modified in anyway. &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;/remarks&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;///&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: green;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: gray;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;&amp;lt;/summary&amp;gt; &lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;public&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;span style="color: blue;"&gt;object&lt;/span&gt; Value { get { &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;And via appropriate documentation. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;&lt;span style=""&gt;&lt;span style=""&gt;3.3&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;No universal annotation format&lt;/h4&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Rather than try to invent a new universal data format for annotations, we decided to be pragmatic. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;So we are limiting ourselves to XML for structural annotations loaded from CSDL (an XML format).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;However since the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;MetadataProperty&lt;/span&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Value &lt;/span&gt;is of type &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: blue; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;object&lt;/span&gt;, in a world where we have an alternative EDM representation (like in memory using mutable metadata for instance) we could easily assign something other than an &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;XElement&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt; &lt;/span&gt;to the &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175); line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;MetadataProperty&lt;/span&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; line-height: 115%;" yes?="" mso-no-proof:="" new?;="" courier=""&gt;Value&lt;/span&gt;, like for example a xaml Serializable CLR type instance. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div style="border-style: solid none none; border-color: rgb(51, 51, 153) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 1pt 0in 0in;"&gt;
&lt;h3&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;4&lt;a class="" title="_Toc205113861" name="_Toc205113861"&gt;&lt;/a&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal;" times="" new="" roman??=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Out of Scope &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;The current plan is to simply support annotation in the CSDL &amp;amp; SSDL. Meaning annotating MSL is currently out of scope. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;If we uncover meaningful important scenarios for MSL annotations, we will undertake that work separately.&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;Incidentally supporting structural annotations in MSL touches a&amp;nbsp;completely separate code path, and as a result will require roughly the same amount of work. Additionally in order to make undertaking this work meaningful we would first need to expose a public mapping metadata API.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;span style=""&gt;....&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;As always we are keen to hear any feedback you have on this item.&lt;/p&gt;
&lt;p&gt;Do you think you will find a use for Structured Annotations?&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, &lt;br&gt;Entity Framework Team&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;this post&lt;/a&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;. &lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8853248" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/EDM/default.aspx">EDM</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Reporting/default.aspx">Reporting</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Evolving+APIs/default.aspx">Evolving APIs</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Metadata/default.aspx">Metadata</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item><item><title>Discussion about API changes necessary for POCO:</title><link>http://blogs.msdn.com/efdesign/archive/2008/08/01/discussion-about-api-changes-necessary-for-poco.aspx</link><pubDate>Fri, 01 Aug 2008 19:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8800626</guid><dc:creator>efdesign</dc:creator><slash:comments>20</slash:comments><comments>http://blogs.msdn.com/efdesign/comments/8800626.aspx</comments><wfw:commentRss>http://blogs.msdn.com/efdesign/commentrss.aspx?PostID=8800626</wfw:commentRss><description>&lt;p&gt;Evolving an API to support new requirements, like POCO, while maintaining backward compatibility is challenging. &lt;/p&gt;
&lt;p&gt;The following design discussion from members of the Object Services team illustrates some of the issues and hard calls involved.&lt;/p&gt;
&lt;p&gt;Have a read, and tell us what you think. &lt;/p&gt;
&lt;p&gt;In particular are we missing something, or overstating the importance of something? Let us know...&lt;/p&gt;
&lt;p&gt;Anyway over to &lt;a href="http://blogs.msdn.com/diego" mce_href="http://blogs.msdn.com/diego"&gt;Diego&lt;/a&gt; and Mirek...&lt;/p&gt;
&lt;h3&gt;POCO API Discussion: Snapshot State Management&lt;/h3&gt;
&lt;p&gt;&lt;b&gt;What is in a snapshot?&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In Entity Framework v1 there is a single way for the state manager to learn about changes in entity instances: the change tracking mechanism is set in such a way that the entity instances themselves notify the state manager of any property change. &lt;/p&gt;
&lt;p&gt;This works seamlessly if you use default code-generated classes, and it is also part of the IPOCO contract for developers willing to create their own entity class hierarchies. &lt;/p&gt;
&lt;p&gt;For version 2, we are currently working on a snapshot-based change tracking mechanism that removes the requirement from classes to send notifications, and enables us to provide full POCO support. &lt;/p&gt;
&lt;p&gt;The basic idea with snapshots is that when you start tracking an entity, a copy of its scalar values is made so that at a later point – typically but not always at the moment of saving changes into the database - you can detect whether anything has changed and needs to be persisted. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;The challenge&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;When we created the v1 API, we made a few assumptions that were totally safe with notification-based change tracking but don’t completely prevail in a snapshot change tracking world. &lt;/p&gt;
&lt;p&gt;We now need to choose the right set of adjustments for the API for it to gracefully adapt to the new scenarios we want to support. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Mainline scenario: SaveChanges() Method&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In notification-based change tracking, by the time SaveChanges is invoked, the required entity state information is ready to use. &lt;/p&gt;
&lt;p&gt;With snapshot thought, a property by property comparison needs to be computed for each tracked entity just to know whether it is unchanged or modified. &lt;/p&gt;
&lt;p&gt;Once the snapshot comparison has taken place, SaveChanges can proceed normally. &lt;/p&gt;
&lt;p&gt;In fact, assuming the process is triggered implicitly on every call to SaveChanges, a typical unit of work in which the program queries and attaches entities, then modifies and adds new entities, and finally persists the changes to the database, works unmodified with POCO classes: &lt;/p&gt;
&lt;p&gt;Category category = context.Categories.First();&lt;/p&gt;
&lt;p&gt;category.Name = "some new name"; // modify existing entity&lt;/p&gt;
&lt;p&gt;Category newCategory = new Category(); // create a new entity&lt;/p&gt;
&lt;p&gt;newCategory.ID = 2;&lt;/p&gt;
&lt;p&gt;newCategory.Name = "new category";&lt;/p&gt;
&lt;p&gt;context.AddObject("Categories", newCategory); // add a new entity&lt;/p&gt;
&lt;p&gt;context.SaveChanges(); // detects all changes before saving&lt;/p&gt;
&lt;p&gt;Things get more complicated when a user wants to use lower level APIs that deal with state management.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;State Manager Public API&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;ObjectStateManager and ObjectStateEntry classes comprise the APIs that you need to deal with if you want to either get input from, or customize the behavior of Entity Framework’s state management in your own code. &lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Typically, you use these APIs if you want to:&lt;/i&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;i&gt;Query for objects that are already loaded into memory&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Manipulate the state of tracked entities&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Validate state transitions or data just before persisting to the database &lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Etc.&lt;/i&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;As the name implies, &lt;b&gt;ObjectStateManager&lt;/b&gt; is Entity Framework’s state manager object, which maintains state and original values for each tracked entity and performs identity management.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;ObjectStateEntries&lt;/i&gt;&lt;/b&gt;&lt;i&gt; represent entities and relationships tracked in the state manager. ObjectStateEntry functions as a wrapper around each tracked entity or relationship and allows you to get its current state (Unchanged, Modified, Added, Deleted and Detached) as well as the current and original values of its properties.&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Needless to say, the primary client for these APIs is the Entity Framework itself. &lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;ObjectStateEntry.State Property&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;The fundamental issue with snapshot is exemplified by this property. &lt;/p&gt;
&lt;p&gt;With notification-based change tracking, the value for the new state is computed on the fly on each notification, and saved to an internal field. Getting the state later only encompasses reading the state from the internal field. &lt;/p&gt;
&lt;p&gt;With snapshot, the state manager no longer gets notifications, and so the actual state at any time depends on the state when the entity began being tracked, whatever state transitions happened, and the current contents of the object. &lt;/p&gt;
&lt;p&gt;&lt;i&gt;Example&lt;/i&gt;: Use ObjectStateEntry to check the current state of the object. &lt;/p&gt;
&lt;p&gt;Category category = context.Categories.First();&lt;/p&gt;
&lt;p&gt;category.Name = "some new name"; // modify existing entity&lt;/p&gt;
&lt;p&gt;ObjectStateEntry entry = context.ObjectStateManager.GetObjectStateEntry(category);&lt;/p&gt;
&lt;p&gt;Console.WriteLine("State of the object: " + entry.State);&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;Question #1: What are the interesting scenarios for using the state management API in POCO scenarios?&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Proposed solutions&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In above example there are two possible behaviors and it's not obvious for us which one is better: &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Alternative 1: Public ObjectStateManager.DetectChanges() Method&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In the first alternative, computation of the snapshot comparison for the whole ObjectStateManager is deferred until a new ObjectStateManager method called DetectChanges is invoked. DetectChanges would iterate through all entities tracked by a state manager and would detects changes in entity's scalar values, references and collections using a snapshot comparison in order to compute the actual state for each ObjectStateEntry. &lt;/p&gt;
&lt;p&gt;In the example below, the first time ObjectStateEntry.State is accessed, it returns EntityState.Unchanged. In order to get a current state of the "category" entity, we would need to invoke DetectChanges first: &lt;/p&gt;
&lt;p&gt;Category category = context.Categories.First();&lt;/p&gt;
&lt;p&gt;category.Name = "some new name"; // modify existing entity&lt;/p&gt;
&lt;p&gt;ObjectStateEntry entry = context.ObjectStateManager.GetObjectStateEntry(category);&lt;/p&gt;
&lt;p&gt;Console.WriteLine("State of the object: " + entry.State); // Displays "Unchanged"&lt;/p&gt;
&lt;p&gt;context.ObjectStateManager.DetectChanges();&lt;/p&gt;
&lt;p&gt;Console.WriteLine("State of the object: " + entry.State); // Displays "Modified"&lt;/p&gt;
&lt;p&gt;DetectChanges would be implicitly invoked from within ObjectContext.SaveChanges. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pros: &lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;· User knows when detection of changes is performed&lt;/p&gt;
&lt;p&gt;· DetectChanges is a method that user would expect to throw exceptions if some constraint is violated&lt;/p&gt;
&lt;p&gt;· This alternative requires minimal changes in Entity Framework current API implementation&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Cons: &lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;· Since DetectChanges iterates through all the ObjectStateEntries, it is a potentially expensive method&lt;/p&gt;
&lt;p&gt;· User has to remember to explicitly call DetectChanges() before using several methods/properties, otherwise, their result will be inaccurate:&lt;/p&gt;
&lt;p&gt;o ObjectStateEntry.State &lt;/p&gt;
&lt;p&gt;o ObjectStateEntry.GetModifiedProperties() &lt;/p&gt;
&lt;p&gt;o ObjectStateManager.GetObjectStateEntries() &lt;/p&gt;
&lt;p&gt;· This alternative implies adding a new method to ObjectStateManager &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Alternative 2: Private ObjectStateEntry.DetectChanges() Method&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In the second alternative, there is no public DetectChanges method. Instead, the computation of the current state of an individual entity or relationship is deferred until state of the entry is accessed. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pros:&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;· User doesn't have to remember explicitly calling DetectChanges to get other APIs to work correctly&lt;/p&gt;
&lt;p&gt;· Existing API works as expected in positive cases regardless of notification-based or snapshot tracking&lt;/p&gt;
&lt;p&gt;· No new public API is added&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Cons:&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;· The following methods now require additional processing to return accurate results in snapshot:&lt;/p&gt;
&lt;p&gt;o ObjectStateEntry.State&lt;/p&gt;
&lt;p&gt;o ObjectStateEntry.GetModifiedProperties()&lt;/p&gt;
&lt;p&gt;o ObjectStateManager.GetObjectStateEntries() &lt;/p&gt;
&lt;p&gt;· Existing API works differently in negative cases in notification-based and snapshot tracking:&lt;/p&gt;
&lt;p&gt;o some of the existing methods would start throwing exceptions&lt;/p&gt;
&lt;p&gt;&lt;i&gt;or&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;o would require to introduce a new state of an entry – Invalid state (see below for details)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;Question #2: What API pattern is better? Having an explicit method to compute the current state based on the snapshot comparisons or having the state to be computed automatically when accessing the state?&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;How this affects other APIs &lt;/b&gt;&lt;/p&gt;
&lt;p&gt;While the State property exemplifies the issue, there are other APIs that would have different behaviors with the two proposed solutions. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;ObjectStateEntry.GetModifiedProperties() Method&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;GetModifiedProperties returns the names of the properties that have been modified in an entity. Similar to the State property, with notification-based change tracking, an internal structure is modified on the fly on each notification. Producing the list later on only encompasses iterating through that structure. &lt;/p&gt;
&lt;p&gt;With snapshot, the state manager no longer gets notifications, and at any given point in time, the actual list of modified properties really depends on a comparison between the original value and the current value of each property. &lt;/p&gt;
&lt;p&gt;Therefore, for alternative #1, this APIs will potentially return wrong results unless it is invoke immediately after DetectChanges. For alternative #2, the behavior would be always correct. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;ObjectStateManager.GetObjectStateEntries()&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This is the case in which an implementation detail that was a good idea for notification-based change tracking stops offering performance benefits in snapshot. Internally, ObjectStateManager stores ObjectStateEntires in separate dictionaries depending on their state. But in snapshot, any unchanged or modified entity can become deleted because of a referential integrity constraint, and any unmodified entity can become modified. &lt;/p&gt;
&lt;p&gt;In alternative #1, DetectChanges would iterate thought the whole contents of the ObjectSateManager, and thus it would update the internal dictionaries. Once this it done, it becomes safe to do in-memory queries using GetObjectStateEntires the same way it is done today. &lt;/p&gt;
&lt;p&gt;In alternative #2, GetObjectStateEntires would need to look in unchanged, modified and deleted storage when asked for deleted entries; also in unchanged and modified storage when asked for modified entities. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Querying with MergeOption.PreserveChanges &lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In Entity Framework, MergeOptions is a setting that changes the behavior of a query with regards to its effects on the state manager. Of all the possibilities, PreserveChanges requires an entity to be in the Unchanged state in order to overwrite it with values coming from the database. In order for PreserveChanges to work correctly, accurate information on the actual state of entities is needed. &lt;/p&gt;
&lt;p&gt;Therefore, with alternative #1, querying with PreserveChanges will not have a correct behavior unless it is done immediately after invoking DetectChanges. For alternative #2, querying with PreserverChanges would behavior correctly at any time. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Referential Integrity constraints&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;When there is a referential integrity constraint defined in the model, a dependent entity may become deleted if the principal entity or the relationship with the principal entity becomes deleted. &lt;/p&gt;
&lt;p&gt;For alternative #1, DetectChanges would also trigger Deletes to propagate downwards throw all referential integrity constraints. &lt;/p&gt;
&lt;p&gt;For alternative #2, finding out the current state of an entity that is dependent in a RIC would requires traversing the graph upwards to find if either the principal entity or a relationship has been deleted. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Mixed Mode Change Tracking&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;At the same time we are working on snapshot change tracking, we are also working on another feature, denominated dynamic proxies. This feature consists of Entity Framework automatically creating derived classes of POCOs that override virtual properties. Overriding properties enables us to inject automatic lazy loading on property getters, and notifications for notification-based change tracking in property setters. This introduces a subtle scenario: when using proxies, it is possible that: &lt;/p&gt;
&lt;p&gt;a. Not all properties in the class are declared virtual. The remaining properties need to still be processed using snapshot. &lt;/p&gt;
&lt;p&gt;b. Sometimes, non-proxy instances of POCOs and proxy instances of the same type have to coexist in the same ObjectStateManager. For the former, it will have to use snapshot tracking. For thelatter, a combination of snapshot and notifications. &lt;/p&gt;
&lt;p&gt;All in all, it becomes clear that the actual state of an entity does not entirely depend on the value of the internal state field, nor on the snapshot comparison, but on a combination of both. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;ObjectStateEntry.SetModified()&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;As with mixed mode change tracking, SetModified() requires a combination of the internal state and the snapshot comparison to return valid results. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Handling of invalid states&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;When working in notification-based change tracking, Entity Framework throws exceptions as soon it learns that entity key values has been modified. With the default code-generated classes, the exception prevents the change for being accepted. &lt;/p&gt;
&lt;p&gt;For alternative #1, DetectChanges can throw exceptions if some model constraint (i.e. key immutability) is violated. It is too late to prevent the value from changing. &lt;/p&gt;
&lt;p&gt;&lt;i&gt;Example&lt;/i&gt;: &lt;/p&gt;
&lt;p&gt;Category category = context.Categories.First();&lt;/p&gt;
&lt;p&gt;category.ID = 123;&amp;nbsp; // Modify a key property. This would throw if category wasn't a POCO class.&lt;/p&gt;
&lt;p&gt;context.ObjectStateManager.DetectChanges(); // Throws because key property change was detected.&lt;/p&gt;
&lt;p&gt;For alternative #2, reading the state of modified properties from an entity with modified keys could throw an exception: &lt;/p&gt;
&lt;p&gt;&lt;i&gt;Example:&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Category category = context.Categories.First();&lt;/p&gt;
&lt;p&gt;category.ID = 123;&amp;nbsp; // Modify a key property. This would throw if category wasn't a POCO class.&lt;/p&gt;
&lt;p&gt;ObjectStateEntry entry = context.ObjectStateManager.GetObjectStateEntry(category);&lt;/p&gt;
&lt;p&gt;Console.WriteLine("State of the object: " + entry.State); &lt;/p&gt;
&lt;p&gt;// Throws because key property change was detected.&lt;/p&gt;
&lt;p&gt;Getting an exception thrown here would be unexpected. But there is an alternative design that is to define a new EntityState that indicates that an entity is &lt;b&gt;Invalid&lt;/b&gt;. This new state would account for the fact that POCO classes per se do not enforce immutable keys. &lt;/p&gt;
&lt;p&gt;Since EntityState is a flag enum, Invalid could be potentially combined with other states. &lt;/p&gt;
&lt;p&gt;SaveChanges would still need to throw an exception if any entity in the state manager is invalid. &lt;/p&gt;
&lt;p&gt;It would be possible to query the state manager for entities in the Invalid state using GetObjectStateEntries method. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;Question #3: Is it better to have an Invalid state for entries or should the state manager just throw exceptions immediately every time it finds a change on a key?&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Our questions:&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;1.&lt;/i&gt;&lt;/b&gt;&lt;i&gt; What are the interesting scenarios for using the state management API in POCO scenarios?&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;2.&lt;/i&gt;&lt;/b&gt;&lt;i&gt; What API pattern is better? Having an explicit method to compute the current state based on the snapshot comparisons or having the state to be computed automatically when accessing the state?&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;3.&lt;/i&gt;&lt;/b&gt;&lt;i&gt; Is it better to have an Invalid state for entries or should the state manager just throw exceptions immediately every time it finds a change on a key?&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;We really want to hear your thoughts on the above questions.&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, &lt;br&gt;Entity Framework Team&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;This post is part of the transparent design exercise in the Entity Framework Team. To understand how it works and how your feedback will be used please look at &lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;a href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx" mce_href="http://blogs.msdn.com/efdesign/archive/2008/06/23/transparency-in-the-design-process.aspx"&gt;this post&lt;/a&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;. &lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8800626" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/POCO/default.aspx">POCO</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Evolving+APIs/default.aspx">Evolving APIs</category><category domain="http://blogs.msdn.com/efdesign/archive/tags/Entity+Framework+4/default.aspx">Entity Framework 4</category></item></channel></rss>