<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>RiaServicesContrib Wiki &amp; Documentation Rss Feed</title><link>http://riaservicescontrib.codeplex.com/Wiki/View.aspx?title=Home</link><description>RiaServicesContrib Wiki Rss Description</description><item><title>New Comment on "T4RIA Documentation"</title><link>https://riaservicescontrib.codeplex.com/wikipage?title=T4RIA Documentation&amp;ANCHOR#C27578</link><description>How to use GeneratedMetadataProvider and attributes on client side&amp;#63;</description><author>valeriuz</author><pubDate>Fri, 24 May 2013 08:56:52 GMT</pubDate><guid isPermaLink="false">New Comment on "T4RIA Documentation" 20130524085652A</guid></item><item><title>Updated Wiki: EntityTools</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=EntityTools&amp;version=6</link><description>&lt;div class="wikidoc"&gt;&lt;h2&gt;Description&lt;/h2&gt;
EntityTools is modeled after Silverlight Contrib/Silverlight Extensions. It currently has a library of extentions for the Entity and EntitySet which provide data import and export abilities.&lt;br /&gt;
&lt;h2&gt;Documentation&lt;/h2&gt;
Online documentation can be found at &lt;a href="http://www.riaservicesblog.net/RiaServicesContrib.EntityTools"&gt;http://www.riaservicesblog.net/RiaServicesContrib.EntityTools&lt;/a&gt;&lt;br /&gt;Offline documentation is available at &lt;a href="http://www.riaservicesblog.net/RiaServicesContrib.EntityTools/Entity%20Tools.chm"&gt;http://www.riaservicesblog.net/RiaServicesContrib.EntityTools/Entity%20Tools.chm&lt;/a&gt;&lt;br /&gt;
&lt;h2&gt;Examples&lt;/h2&gt;
&lt;h3&gt;Entity cloning&lt;/h3&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
Person newPerson = newPerson();
newPerson.ApplyState(Nothing, existingPerson.ExtractState(ExtractType.ModifiedState);
newPerson.PersonId = Guid.NewGuid();
context.Persons.Add(newPerson);
&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Partial Save (i.e. save only a single change instead of the whole DomainContext)&lt;/h3&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
PersonDomainContext tempContext = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; PersonDomainContext();
Person savePerson = newPerson();
tempContext.Persons.Add(savePerson);
savePerson.ApplyState(originalPerson.ExtractState(ExtractType.OriginalState, ExtractType.ModifiedState);
tempContext.SubmitChanges();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;A more powerful example of performing a partial save can be found at &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;amp;referringTitle=EntityGraphs%20"&gt;http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;amp;referringTitle=EntityGraphs%20&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Export EntityList and save to Isolated Storage&lt;/h3&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()
{
    &lt;span style="color:Blue;"&gt;using&lt;/span&gt; IsolatedStorageFileStream isfs = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, isf)
    {
        DataContractSerializer serializer = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(List&amp;lt;EntityStateSet&amp;gt;));
        serializer.WriteObject(isfs, context.Persons.Export());
        isfs.Close();
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Import information from Isolated Storage into EntityList&lt;/h3&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()
{
    &lt;span style="color:Blue;"&gt;using&lt;/span&gt; IsolatedStorageFileStream isfs = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; IsolatedStorageFileStream(fileName, FileMode.Open, isf)
    {
        DataContractSerializer serializer = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; DataContractSerializer(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(List&amp;lt;EntityStateSet&amp;gt;));
        context.Persons.Import(serializer.ReadObject(isfs));
        isfs.Close();
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Some things which might not be obvious is that the Export functionality can also be done against a LINQ query, allowing partial exports of entities. &lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>ColinBlair</author><pubDate>Thu, 23 Aug 2012 18:53:22 GMT</pubDate><guid isPermaLink="false">Updated Wiki: EntityTools 20120823065322P</guid></item><item><title>Updated Wiki: FluentMetadata for WCF RIA Services </title><link>http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata for WCF RIA Services &amp;version=9</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;FluentMetadata, a Fluent API for defining metadata for WCF RIA Services entities&lt;/h1&gt;
With permission of Nikhil Kothari, I&amp;#39;ve added the source code of Nikhil&amp;#39;s Fluent API for defining WCF Ria Services Metadata to RIA Services Contrib. I&amp;#39;ve made a couple of changes. Most noticeable is the ability to attach a MetadataClass to your domain service using the FluentMetadata attribute. This class mimics the OnModelCreating method in EntityFramework DbContext and allows you to instantiate your Metadata classes. The original version is available &lt;a href="http://www.nikhilk.net/RIA-Services-Fluent-Metadata-API.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The main advantage of this package is that it allows you to separate your datamodel and metadata in separate projects/assemblies. This is not possible with the standard RIA services approach of buddy classes. These have to be defined in the same project as your datamodel. The drawbacks of this are a pollution of your datamodel and (most importantly) that your datamodel project becomes dependent on RIA services-specific assemblies. With the FluentMetadata package you can define metadata in any assembly you like.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Download&lt;/b&gt;: the package is available as a &lt;a href="http://nuget.org/List/Packages/FluentMetadata"&gt;Nuget package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Changes in version 0.2.69239.0&lt;/b&gt;
&lt;ul&gt;&lt;li&gt;The fluent API now supports defining associations, e.g. &lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
metadataContainer.Entity&amp;lt;Bar&amp;gt;()
    .Projection(x =&amp;gt; x.FooSet)
        .Association()
            .WithName(&lt;span style="color:#A31515;"&gt;&amp;quot;MyAssociation&amp;quot;&lt;/span&gt;)
            .WithThisKey(x =&amp;gt; x.Id2, x=&amp;gt;x.Id)
            .WithOtherKey(x =&amp;gt; x.Id2, x=&amp;gt;x.Id);
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Metadata can be defined in a Metadata class per type or directly in your IFluentMetadataConfiguration &lt;/li&gt;
&lt;li&gt;The Fluent API is more open such that it can be extended in third-party libraries &lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;b&gt;Using FluentMetadata&lt;/b&gt;
&lt;ul&gt;&lt;li&gt;Install the FluentMetadata Nuget package (or download its source code)&lt;/li&gt;
&lt;li&gt;Define a MetadataConfiguration class containing the fluent metadata for your entities. For example:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Entity&amp;lt;Foo&amp;gt;().Projection(x =&amp;gt; x.SomeProperty).Exclude();
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;&lt;li&gt;Alternatively, you can define the metadat for each entity in separate MetadataClass classes. For example&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FooMetadata : MetadataClass&amp;lt;Foo&amp;gt;
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; FooMetadata()
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Projection(x =&amp;gt; x.ExcludedString).Exclude();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RequiredString).Required();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RegularExpressionString).RegularExpression(&lt;span style="color:#A31515;"&gt;&amp;quot;[a-z]&amp;quot;&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... and instantiate it from your FluentMetadataConfiguration  class, like so:&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Add(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; FooMetadata());
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... both mechanisms can be combined.&lt;/li&gt;
&lt;li&gt;Lastly, add the FluentMetadata attribute to your domain service:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
[EnableClientAccess()]
[FluentMetadata(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(FluentMetadataConfiguration))]
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataTestDomainService : DomainService
{
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Tue, 05 Jun 2012 12:21:26 GMT</pubDate><guid isPermaLink="false">Updated Wiki: FluentMetadata for WCF RIA Services  20120605122126P</guid></item><item><title>Updated Wiki: FluentMetadata for WCF RIA Services </title><link>http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata for WCF RIA Services &amp;version=8</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;FluentMetadata, a Fluent API for defining metadata for WCF RIA Services entities&lt;/h1&gt;
With permission of Nikhil Kothari, I&amp;#39;ve added the source code of Nikhil&amp;#39;s Fluent API for defining WCF Ria Services Metadata to RIA Services Contrib. I&amp;#39;ve made a couple of changes. Most noticeable is the ability to attach a MetadataClass to your domain service using the FluentMetadata attribute. This class mimics the OnModelCreating method in EntityFramework DbContext and allows you to instantiate your Metadata classes. The original version is available &lt;a href="http://www.nikhilk.net/RIA-Services-Fluent-Metadata-API.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The main advantage of this package is that it allows you to separate your datamodel and metadata in separate projects/assemblies. This is not possible with the standard RIA services approach of buddy classes. These have to be defined in the same project as your datamodel. The drawbacks of this are a pollution of your datamodel and (most importantly) that your datamodel project becomes dependent on RIA services-specific assemblies. With the FluentMetadata package you can define metadata in any assembly you like.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Download&lt;/b&gt;: the package is available as a &lt;a href="http://nuget.org/List/Packages/FluentMetadata"&gt;Nuget package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Changes in the latest release&lt;/b&gt;
&lt;ul&gt;&lt;li&gt;The fluent API now supports defining associations&lt;/li&gt;
&lt;li&gt;Metadata can be defined in a Metadata class per type or directly in your IFluentMetadataConfiguration &lt;/li&gt;
&lt;li&gt;The Fluent API is more open such that it can be extended in third-party libraries &lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;To make use of FluentMetadata:
&lt;ul&gt;&lt;li&gt;Install the FluentMetadata Nuget package (or download its source code)&lt;/li&gt;
&lt;li&gt;Define a MetadataConfiguration class containing the fluent metadata for your entities. For example:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Entity&amp;lt;Foo&amp;gt;().Projection(x =&amp;gt; x.SomeProperty).Exclude();
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;&lt;li&gt;Alternatively, you can define the metadat for each entity in separate MetadataClass classes. For example&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FooMetadata : MetadataClass&amp;lt;Foo&amp;gt;
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; FooMetadata()
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Projection(x =&amp;gt; x.ExcludedString).Exclude();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RequiredString).Required();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RegularExpressionString).RegularExpression(&lt;span style="color:#A31515;"&gt;&amp;quot;[a-z]&amp;quot;&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... and instantiate it from your FluentMetadataConfiguration  class, like so:&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Add(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; FooMetadata());
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... both mechanisms can be combined.&lt;/li&gt;
&lt;li&gt;Lastly, add the FluentMetadata attribute to your domain service:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
[EnableClientAccess()]
[FluentMetadata(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(FluentMetadataConfiguration))]
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataTestDomainService : DomainService
{
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Mon, 04 Jun 2012 20:48:59 GMT</pubDate><guid isPermaLink="false">Updated Wiki: FluentMetadata for WCF RIA Services  20120604084859P</guid></item><item><title>Updated Wiki: FluentMetadata for WCF RIA Services </title><link>http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata for WCF RIA Services &amp;version=7</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;FluentMetadata, a Fluent API for defining metadata for WCF RIA Services entities&lt;/h1&gt;
With permission of Nikhil Kothari, I&amp;#39;ve added the source code of Nikhil&amp;#39;s Fluent API for defining WCF Ria Services Metadata to RIA Services Contrib. I&amp;#39;ve made a couple of changes. Most noticeable is the ability to attach a MetadataClass to your domain service using the FluentMetadata attribute. This class mimics the OnModelCreating method in EntityFramework DbContext and allows you to instantiate your Metadata classes. The original version is available &lt;a href="http://www.nikhilk.net/RIA-Services-Fluent-Metadata-API.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The main advantage of this package is that it allows you to separate your datamodel and metadata in separate projects/assemblies. This is not possible with the standard RIA services approach of buddy classes. These have to be defined in the same project as your datamodel. The drawbacks of this are a pollution of your datamodel and (most importantly) that your datamodel project becomes dependent on RIA services-specific assemblies. With the FluentMetadata package you can define metadata in any assembly you like.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Download&lt;/b&gt;: the package is available as a &lt;a href="http://nuget.org/List/Packages/FluentMetadata"&gt;Nuget package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;To make use of FluentMetadata:
&lt;ul&gt;&lt;li&gt;Install the FluentMetadata Nuget package (or download its source code)&lt;/li&gt;
&lt;li&gt;Define a MetadataConfiguration class containing the fluent metadata for your entities. For example:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Entity&amp;lt;Foo&amp;gt;().Projection(x =&amp;gt; x.SomeProperty).Exclude();
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;&lt;li&gt;Alternatively, you can define the metadat for each entity in separate MetadataClass classes. For example&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FooMetadata : MetadataClass&amp;lt;Foo&amp;gt;
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; FooMetadata()
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Projection(x =&amp;gt; x.ExcludedString).Exclude();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RequiredString).Required();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RegularExpressionString).RegularExpression(&lt;span style="color:#A31515;"&gt;&amp;quot;[a-z]&amp;quot;&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... and instantiate it from your FluentMetadataConfiguration  class, like so:&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Add(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; FooMetadata());
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... both mechanisms can be combined.&lt;/li&gt;
&lt;li&gt;Lastly, add the FluentMetadata attribute to your domain service:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
[EnableClientAccess()]
[FluentMetadata(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(FluentMetadataConfiguration))]
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataTestDomainService : DomainService
{
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Mon, 04 Jun 2012 20:45:42 GMT</pubDate><guid isPermaLink="false">Updated Wiki: FluentMetadata for WCF RIA Services  20120604084542P</guid></item><item><title>Updated Wiki: FluentMetadata for WCF RIA Services </title><link>http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata for WCF RIA Services &amp;version=6</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;FluentMetadata, a Fluent API for defining metadata for WCF RIA Services entities&lt;/h1&gt;
With permission of Nikhil Kothari, I&amp;#39;ve added the source code of Nikhil&amp;#39;s Fluent API for defining WCF Ria Services Metadata to RIA Services Contrib. I&amp;#39;ve made a couple of changes. Most noticeable is the ability to attach a MetadataClass to your domain service using the FluentMetadata attribute. This class mimics the OnModelCreating method in EntityFramework DbContext and allows you to instantiate your Metadata classes. The original version is available &lt;a href="http://www.nikhilk.net/RIA-Services-Fluent-Metadata-API.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The main advantage of this package is that it allows you to separate your datamodel and metadata in separate projects/assemblies. This is not possible with the standard RIA services approach of buddy classes. These have to be defined in the same project as your datamodel. The drawbacks of this are a pollution of your datamodel and (most importantly) that your datamodel project becomes dependent on RIA services-specific assemblies. With the FluentMetadata package you can define metadata in any assembly you like.&lt;br /&gt;&lt;br /&gt;The package is also available as a &lt;a href="http://nuget.org/List/Packages/FluentMetadata"&gt;Nuget package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;To make use of FluentMetadata:
&lt;ul&gt;&lt;li&gt;Install the FluentMetadata Nuget package (or download its source code)&lt;/li&gt;
&lt;li&gt;Define a MetadataConfiguration class containing the fluent metadata for your entities. For example:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Entity&amp;lt;Foo&amp;gt;().Projection(x =&amp;gt; x.SomeProperty).Exclude();
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;&lt;li&gt;Alternatively, you can define the metadat for each entity in separate MetadataClass classes. For example&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FooMetadata : MetadataClass&amp;lt;Foo&amp;gt;
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; FooMetadata()
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Projection(x =&amp;gt; x.ExcludedString).Exclude();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RequiredString).Required();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RegularExpressionString).RegularExpression(&lt;span style="color:#A31515;"&gt;&amp;quot;[a-z]&amp;quot;&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... and instantiate it from your FluentMetadataConfiguration  class, like so:&lt;/li&gt;&lt;/ul&gt;
&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Add(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; FooMetadata());
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;... both mechanisms can be combined.&lt;/li&gt;
&lt;li&gt;Lastly, add the FluentMetadata attribute to your domain service:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
[EnableClientAccess()]
[FluentMetadata(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(FluentMetadataConfiguration))]
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataTestDomainService : DomainService
{
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Mon, 04 Jun 2012 20:23:16 GMT</pubDate><guid isPermaLink="false">Updated Wiki: FluentMetadata for WCF RIA Services  20120604082316P</guid></item><item><title>Updated Wiki: Documentation</title><link>http://riaservicescontrib.codeplex.com/documentation?version=7</link><description>&lt;div class="wikidoc"&gt;For documentation about the features of WVF RIA Services Contrib click on one of the links below:&lt;br /&gt;&lt;br /&gt; * &lt;a href="http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx"&gt;ComboBoxExtensions&lt;/a&gt; &lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Documentation"&gt;Data Validation Framework&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityTools&amp;referringTitle=Documentation"&gt;Entity Tools&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Documentation"&gt;EntityGraph&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata%20for%20WCF%20RIA%20Services&amp;referringTitle=Documentation"&gt;FluentMetadata for WCF RIA Services&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=T4RIA&amp;referringTitle=Documentation"&gt;T4RIA&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Sun, 25 Mar 2012 20:22:54 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120325082254P</guid></item><item><title>Updated Wiki: Documentation</title><link>http://riaservicescontrib.codeplex.com/documentation?version=6</link><description>&lt;div class="wikidoc"&gt;For documentation about the features of WVF RIA Services Contrib click on one of the links below:&lt;br /&gt;&lt;br /&gt; * &lt;a href="http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx"&gt;ComboBoxExtensions&lt;/a&gt; &lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Documentation"&gt;Data Validation Framework&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityTools&amp;referringTitle=Documentation"&gt;Entity Tools&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Documentation"&gt;EntityGraph&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata&amp;referringTitle=Documentation"&gt;FluentMetadata&lt;/a&gt;&lt;br /&gt; * &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=T4RIA&amp;referringTitle=Documentation"&gt;T4RIA&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Sun, 25 Mar 2012 20:21:09 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120325082109P</guid></item><item><title>Updated Wiki: Home</title><link>http://riaservicescontrib.codeplex.com/wikipage?version=30</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Project Description&lt;/h1&gt;WCF RIA Services Contrib is a collection of tools for WCF RIA Services. Contributions are welcome.&lt;br /&gt;&lt;br /&gt;WCF RIA Services Contrib has the following features:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt; &lt;a href="http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx"&gt;ComboBoxExtensions&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extensions to ComboBox that add asynchronous loading, cascading ComboBoxes and support for Entity associations to ComboBoxes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;Data Validation Framework&lt;/a&gt;&lt;/td&gt;&lt;td&gt; Is a generic validation framework that is much more flexible and feature-rich than the validation framework of WCF RIA Services.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityTools&amp;referringTitle=Home"&gt;Entity Tools&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extension methods that add state manipulation functionality (such as cloning) to entities. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;EntityGraph&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a technology to separate generic operations (such as cloning iterating, validation) from your data model. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata%20for%20WCF%20RIA%20Services&amp;referringTitle=Home"&gt;FluentMetadata&lt;/a&gt; &lt;/td&gt;&lt;td&gt; A Fluent API for defining metadata for WCF RIA Services entities.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=T4RIA&amp;referringTitle=Home"&gt;T4RIA&lt;/a&gt; &lt;/td&gt;&lt;td&gt;is a T4 template that generates domain services, metadata and localization for WCF RIA Services from ADO.NET Entity Data Model.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;
&lt;h1&gt;Download and install&lt;/h1&gt;WCF RIA Services is available in the following forms:
&lt;ul&gt;&lt;li&gt;Source code. If you need the most recent stuff of WCF RIA Services Contrib, or if you want to make (and contribute) your own changes, checking out the source code &lt;a href="http://riaservicescontrib.codeplex.com/SourceControl/list/changesets"&gt;here&lt;/a&gt; is the way to go.&lt;/li&gt;
&lt;li&gt;NuGet. This is the prefered way of using WCF RIA Services Contrib  because it allows you to use only those parts that you need, because installation is very simple, and because most NuGet packages are released more frequently then the binary release of WCF RIA Services Contrib, described below. The following sub-components of WCF RIA Services Contrib are distributed as NuGet Packages:
&lt;ul&gt;&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/RiaServicesContrib.EntityTools"&gt;EntityTools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/DataValidationFramework"&gt;DataValidationFramework&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/EntityGraph"&gt;EntityGraph&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/FluentMetadata"&gt;FluentMetadata&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Binary zip file. This bundles EntityTools, ComboBoxExtensions, and T4RIA. You can obtain this distribution via the &lt;a href="http://riaservicescontrib.codeplex.com/releases"&gt;Downloads&lt;/a&gt; tab. The zip file is no longer being maintained.&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Please Contribute&lt;/h1&gt;If you have any RIA Services related code which you would like to add to this project please let me know. I welcome anyone willing to contribute.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Sun, 25 Mar 2012 20:20:26 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120325082026P</guid></item><item><title>Updated Wiki: FluentMetadata for WCF RIA Services </title><link>http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata for WCF RIA Services &amp;version=5</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;FluentMetadata, a Fluent API for defining metadata for WCF RIA Services entities&lt;/h1&gt;
With permission of Nikhil Kothari, I&amp;#39;ve added the source code of Nikhil&amp;#39;s Fluent API for defining WCF Ria Services Metadata to RIA Services Contrib. I&amp;#39;ve made a couple of changes. Most noticeable is the ability to attach a MetadataClass to your domain service using the FluentMetadata attribute. This class mimics the OnModelCreating method in EntityFramework DbContext and allows you to instantiate your Metadata classes. The original version is available &lt;a href="http://www.nikhilk.net/RIA-Services-Fluent-Metadata-API.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The main advantage of this package is that it allows you to separate your datamodel and metadata in separate projects/assemblies. This is not possible with the standard RIA services approach of buddy classes. These have to be defined in the same project as your datamodel. The drawbacks of this are a pollution of your datamodel and (most importantly) that you datamodel project becomes dependent on RIA services-specific assemblies. With the FluentMetadata package you can define metadata in any assembly you like.&lt;br /&gt;&lt;br /&gt;The package is also available as a &lt;a href="http://nuget.org/List/Packages/FluentMetadata"&gt;Nuget package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;To make use of FluentMetadata:
&lt;ul&gt;&lt;li&gt;Install the FluentMetadata Nuget package (or download its source code)&lt;/li&gt;
&lt;li&gt;Define metadata classes for your entities (this is pretty similar to EntityFramework). For example:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FooMetadata : MetadataClass&amp;lt;Foo&amp;gt;
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; FooMetadata()
    {
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Projection(x =&amp;gt; x.ExcludedString).Exclude();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RequiredString).Required();
        &lt;span style="color:Blue;"&gt;this&lt;/span&gt;.Validation(x =&amp;gt; x.RegularExpressionString).RegularExpression(&lt;span style="color:#A31515;"&gt;&amp;quot;[a-z]&amp;quot;&lt;/span&gt;);
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Define a MetadataConfiguration class that instantiates all your metadata classes. For example:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataConfiguration : IFluentMetadataConfiguration
{
    &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; OnTypeCreation(MetadataContainer metadataContainer)
    {
        metadataContainer.Add(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; FooMetadata());
    }
}
&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;&lt;li&gt;Add the FluentMetadata attribute to your domain service:&lt;/li&gt;&lt;/ul&gt;
&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
[EnableClientAccess()]
[FluentMetadata(&lt;span style="color:Blue;"&gt;typeof&lt;/span&gt;(FluentMetadataConfiguration))]
&lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;class&lt;/span&gt; FluentMetadataTestDomainService : DomainService
{
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Sun, 25 Mar 2012 20:19:49 GMT</pubDate><guid isPermaLink="false">Updated Wiki: FluentMetadata for WCF RIA Services  20120325081949P</guid></item><item><title>Updated Wiki: Home</title><link>http://riaservicescontrib.codeplex.com/wikipage?version=29</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Project Description&lt;/h1&gt;WCF RIA Services Contrib is a collection of tools for WCF RIA Services. Contributions are welcome.&lt;br /&gt;&lt;br /&gt;WCF RIA Services Contrib has the following features:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt; &lt;a href="http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx" class="externalLink"&gt;ComboBoxExtensions&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extensions to ComboBox that add asynchronous loading, cascading ComboBoxes and support for Entity associations to ComboBoxes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;Data Validation Framework&lt;/a&gt;&lt;/td&gt;&lt;td&gt; Is a generic validation framework that is much more flexible and feature-rich than the validation framework of WCF RIA Services.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityTools&amp;referringTitle=Home"&gt;Entity Tools&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extension methods that add state manipulation functionality (such as cloning) to entities. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;EntityGraph&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a technology to separate generic operations (such as cloning iterating, validation) from your data model. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata%20for%20WCF%20RIA%20Services&amp;referringTitle=Home"&gt;FluentMetadata&lt;/a&gt; &lt;/td&gt;&lt;td&gt; A package that enables to define metadata for entities using a Fluent API.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=T4RIA&amp;referringTitle=Home"&gt;T4RIA&lt;/a&gt; &lt;/td&gt;&lt;td&gt;is a T4 template that generates domain services, metadata and localization for WCF RIA Services from ADO.NET Entity Data Model.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;
&lt;h1&gt;Download and install&lt;/h1&gt;WCF RIA Services is available in the following forms:
&lt;ul&gt;&lt;li&gt;Source code. If you need the most recent stuff of WCF RIA Services Contrib, or if you want to make (and contribute) your own changes, checking out the source code &lt;a href="http://riaservicescontrib.codeplex.com/SourceControl/list/changesets" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is the way to go.&lt;/li&gt;
&lt;li&gt;NuGet. This is the prefered way of using WCF RIA Services Contrib  because it allows you to use only those parts that you need, because installation is very simple, and because most NuGet packages are released more frequently then the binary release of WCF RIA Services Contrib, described below. The following sub-components of WCF RIA Services Contrib are distributed as NuGet Packages:
&lt;ul&gt;&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/RiaServicesContrib.EntityTools" class="externalLink"&gt;EntityTools&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/DataValidationFramework" class="externalLink"&gt;DataValidationFramework&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/EntityGraph" class="externalLink"&gt;EntityGraph&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/FluentMetadata" class="externalLink"&gt;FluentMetadata&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Binary zip file. This bundles EntityTools, ComboBoxExtensions, and T4RIA. You can obtain this distribution via the &lt;a href="http://riaservicescontrib.codeplex.com/releases" class="externalLink"&gt;Downloads&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; tab. The zip file is no longer being maintained.&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Please Contribute&lt;/h1&gt;If you have any RIA Services related code which you would like to add to this project please let me know. I welcome anyone willing to contribute.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>ColinBlair</author><pubDate>Tue, 14 Feb 2012 16:01:17 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120214040117P</guid></item><item><title>Updated Wiki: Home</title><link>http://riaservicescontrib.codeplex.com/wikipage?version=28</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Project Description&lt;/h1&gt;WCF RIA Services Contrib is a collection of tools for WCF RIA Services. Contributions are welcome.&lt;br /&gt;&lt;br /&gt;WCF RIA Services Contrib has the following features:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt; &lt;a href="http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx" class="externalLink"&gt;ComboBoxExtensions&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extensions to ComboBox that add asynchronous loading, cascading ComboBoxes and support for Entity associations to ComboBoxes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;Data Validation Framework&lt;/a&gt;&lt;/td&gt;&lt;td&gt; Is a generic validation framework that is much more flexible and feature-rich than the validation framework of WCF RIA Services.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityTools&amp;referringTitle=Home"&gt;Entity Tools&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extension methods that add state manipulation functionality (such as cloning) to entities. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;EntityGraph&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a technology to separate generic operations (such as cloning iterating, validation) from your data model. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata%20for%20WCF%20RIA%20Services&amp;referringTitle=Home"&gt;FluentMetadata&lt;/a&gt; &lt;/td&gt;&lt;td&gt; A package that enables to define metadata for entities using a Fluent API.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=T4RIA&amp;referringTitle=Home"&gt;T4RIA&lt;/a&gt; &lt;/td&gt;&lt;td&gt;is a T4 template that generates domain services, metadata and localization for WCF RIA Services from ADO.NET Entity Data Model.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;
&lt;h1&gt;Download and install&lt;/h1&gt;WCF RIA Services is available in the following forms:
&lt;ul&gt;&lt;li&gt;Source code. If you need the most recent stuff of WCF RIA Services Contrib, or if you want to make (and contribute) your own changes, checking out the source code &lt;a href="http://riaservicescontrib.codeplex.com/SourceControl/list/changesets" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; is the way to go.&lt;/li&gt;
&lt;li&gt;NuGet. This is the prefered way of using WCF RIA Services Contrib  because it allows you to use only those parts that you need, because installation is very simple, and because most NuGet packages are released more frequently then the binary release of WCF RIA Services Contrib, described below. The following sub-components of WCF RIA Services Contrib are distributed as NuGet Packages:
&lt;ul&gt;&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/RiaServicesContrib.EntityTools" class="externalLink"&gt;EntityTools&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/DataValidationFramework" class="externalLink"&gt;DataValidationFramework&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/EntityGraph" class="externalLink"&gt;EntityGraph&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/FluentMetadata" class="externalLink"&gt;FluentMetadata&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Binary zip file. This bundles EntityTools, ComboBoxExtensions, and T4RIA. You can obtain this distribution via the &lt;a href="http://riaservicescontrib.codeplex.com/releases" class="externalLink"&gt;Downloads&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; tab.&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Please Contribute&lt;/h1&gt;If you have any RIA Services related code which you would like to add to this project please let me know. I welcome anyone willing to contribute.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Thu, 01 Dec 2011 10:38:59 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111201103859A</guid></item><item><title>Updated Wiki: Home</title><link>http://riaservicescontrib.codeplex.com/wikipage?version=27</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Project Description&lt;/h1&gt;WCF RIA Services Contrib is a collection of tools for WCF RIA Services. Contributions are welcome.&lt;br /&gt;&lt;br /&gt;WCF RIA Services Contrib has the following features:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt; &lt;a href="http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx" class="externalLink"&gt;ComboBoxExtensions&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extensions to ComboBox that add asynchronous loading, cascading ComboBoxes and support for Entity associations to ComboBoxes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;Data Validation Framework&lt;/a&gt;&lt;/td&gt;&lt;td&gt; Is a generic validation framework that is much more flexible and feature-rich than the validation framework of WCF RIA Services.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityTools&amp;referringTitle=Home"&gt;Entity Tools&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a collection of extension methods that add state manipulation functionality (such as cloning) to entities. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&amp;referringTitle=Home"&gt;EntityGraph&lt;/a&gt; &lt;/td&gt;&lt;td&gt; Is a technology to separate generic operations (such as cloning iterating, validation) from your data model. &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=FluentMetadata%20for%20WCF%20RIA%20Services&amp;referringTitle=Home"&gt;FluentMetadata&lt;/a&gt; &lt;/td&gt;&lt;td&gt; A package that enables to define metadata for entities using a Fluent API.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=T4RIA&amp;referringTitle=Home"&gt;T4RIA&lt;/a&gt; &lt;/td&gt;&lt;td&gt;is a T4 template that generates domain services, metadata and localization for WCF RIA Services from ADO.NET Entity Data Model.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;
&lt;h1&gt;Download and install&lt;/h1&gt;WCF RIA Services is available in the following forms:
&lt;ul&gt;&lt;li&gt;Source code. If you need the most recent stuff of WCF RIA Services Contrib, or if you want to make (and contribute) your own changes, checking out the source code &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=SourceControl&amp;referringTitle=Home"&gt;here&lt;/a&gt; is the way to go.&lt;/li&gt;
&lt;li&gt;NuGet. This is the prefered way of using WCF RIA Services Contrib  because it allows you to use only those parts that you need, because installation is very simple, and because most NuGet packages are released more frequently then the binary release of WCF RIA Services Contrib, described below. The following sub-components of WCF RIA Services Contrib are distributed as NuGet Packages:
&lt;ul&gt;&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/RiaServicesContrib.EntityTools" class="externalLink"&gt;EntityTools&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/DataValidationFramework" class="externalLink"&gt;DataValidationFramework&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/EntityGraph" class="externalLink"&gt;EntityGraph&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nuget.org/List/Packages/FluentMetadata" class="externalLink"&gt;FluentMetadata&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Binary zip file. This bundles EntityTools, ComboBoxExtensions, and T4RIA. &lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Please Contribute&lt;/h1&gt;If you have any RIA Services related code which you would like to add to this project please let me know. I welcome anyone willing to contribute.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Thu, 01 Dec 2011 10:14:12 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111201101412A</guid></item><item><title>Updated Wiki: PartialSaveWithEntityGraph</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;version=9</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;How to partially save entities in your domain context?&lt;/h1&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;A RIA services domain context is used to manage your entities and to submit changes to your domain service following the unit of work pattern. The domain context gives little or no control over what entities are going to be communicated to a domain service when the &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; method is invoked. There are many situations where just submitting all pending changes is too coarse grained. In this post I will explain how EntityGraph can give control over which entities are submitted to your domain context (&lt;b&gt;but see &lt;a href="#Disclaimer"&gt;Disclaimer&lt;/a&gt; below&lt;/b&gt;).&lt;br /&gt;
&lt;h3&gt;EntityGraph in a Nutshell&lt;/h3&gt;An entity graph is defined as a collection of entities connected through their associations that forms a logical unit. An entity graph is defined by means of an entity graph shape. For example:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; shape = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraphShape()
   .Edge&amp;lt;Car, Wheel&amp;gt;(x =&amp;gt; Wheels)
   .Edge&amp;lt;Car, Engine&amp;gt;(x =&amp;gt; Engine);
&lt;/pre&gt;&lt;/div&gt;This defines the shape of an entity graph spanning the associations between &lt;span class="codeInline"&gt;Car&lt;/span&gt;, its &lt;span class="codeInline"&gt;Wheels&lt;/span&gt;, and its &lt;span class="codeInline"&gt;Engine&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Given an &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance called &lt;span class="codeInline"&gt;car&lt;/span&gt;, we can create a corresponding EntityGraph as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; graph = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraph(car, shape);
&lt;/pre&gt;&lt;/div&gt;There are many things you can now do with this entity graph. E.g., see &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs" class="externalLink"&gt;http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For partial save I&amp;#39;m going to focus on the &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. I.e., we can create a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone();
&lt;/pre&gt;&lt;/div&gt;This example creates an identical copy of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities that are reachable according to the edges in &lt;span class="codeInline"&gt;shape&lt;/span&gt; (i.e., it includes identical copies of the wheels and the engine of the car). &lt;br /&gt;
&lt;h3&gt;Implementing Partial Save&lt;/h3&gt;Lets assume that &lt;span class="codeInline"&gt;car&lt;/span&gt; is contained in the domain context &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; and that we want to submit the changes of this single &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance together with its associated wheels and engine. This basically means that we want to submit only the pending changes for the entities contained in the entity graph we just created. Of course, we can&amp;#39;t just call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; because that may also submit pending changes of entities that are not part of the graph.&lt;br /&gt;&lt;br /&gt;For a partial save of &lt;span class="codeInline"&gt;car&lt;/span&gt;, this is what we are going to do:
&lt;ol&gt;&lt;li&gt;Create a new instance of &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; called &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Duplicate the entity graph for &lt;span class="codeInline"&gt;car&lt;/span&gt; in this new context&lt;/li&gt;
&lt;li&gt;Call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;On success, synchronize the entities in the original domain context with the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;.&lt;/li&gt;&lt;/ol&gt;
A clone cannot be present in the same domain context as its source. The reason is that the cloned entities have the same primary keys. Adding them will lead to an exception indicating that an entity with the same key is already present in the context. The &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method that we used above therefore returns a cloned entity (and its associations) that is not attached to any domain context. A consequence is that the cloned entities no longer contain state information (since they are not managed by a context). They all have an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Detached&lt;/span&gt;. Attaching them to &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will give them an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;. &lt;span class="codeInline"&gt;HasChanges&lt;/span&gt; will return &lt;span class="codeInline"&gt;false&lt;/span&gt; and calling &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; will have no effect. This is clearly not what we have in mind for a partial save method.&lt;br /&gt;&lt;br /&gt;In order to make a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; that includes proper state information, the cloned entities must be attached to a domain context. For this purpose, EntityGraph also provides a state-preserving &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. It attaches the cloned entities to another context and restores the entity state. This is the method we&amp;#39;re going to use:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; partialSaveContext = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CarExampleContext();
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone(partialSaveContext);
&lt;/pre&gt;&lt;/div&gt;After calling &lt;span class="codeInline"&gt;Clone()&lt;/span&gt;, &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will contain a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities in this domain context have the same &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; as the entities in the entity graph &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This means that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;true&lt;/span&gt; and that we can now call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the context:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
partialSaveContext.SubmitChanges();
&lt;/pre&gt;&lt;/div&gt;This will submit the pending changes of the cloned entity graph rooted at &lt;span class="codeInline"&gt;car&lt;/span&gt; to the server. Nothing more, nothing less. &lt;br /&gt;&lt;br /&gt;If &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; completes without an error, you can verify that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;false&lt;/span&gt;, as expected. However, the original context still has changes pending. This can be observed by inspecting &lt;span class="codeInline"&gt;context.HasChanges&lt;/span&gt; and &lt;span class="codeInline"&gt;graph.HasChanges&lt;/span&gt;. Both properties yield &lt;span class="codeInline"&gt;true&lt;/span&gt;. This is because the source domain context still contains the original entities with their changes pending. Moreover, since we&amp;#39;ve submitted the changes to the server, some of the properties of the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; may have been updated with server-provided values (this is for instance the case with generated keys). As a final step we therefore have to synchronize the entities in the original context with the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;. This can be done with the &lt;span class="codeInline"&gt;Synchronize&lt;/span&gt; method of EntityGraph:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
graph.Synchronize(clone);
&lt;/pre&gt;&lt;/div&gt;This updates the entities in the EntityGraph &lt;span class="codeInline"&gt;graph&lt;/span&gt; according to the entities in the EntityGraph &lt;span class="codeInline"&gt;clone&lt;/span&gt;. This includes updating the entity states. As a result, &lt;span class="codeInline"&gt;graph&lt;/span&gt; and &lt;span class="codeInline"&gt;clone&lt;/span&gt; are identical clones and both have no more pending changes (you can verify that all entities in &lt;span class="codeInline"&gt;graph&lt;/span&gt; have their &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; set to &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;, exactly what is needed. This completes the partial save mechanism. Observe that &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; is no longer needed.&lt;br /&gt;&lt;a name="Disclaimer"&gt;&lt;/a&gt;
&lt;h3&gt;Disclaimer&lt;/h3&gt;There is one situation where the partial save method will/can &lt;i&gt;not&lt;/i&gt; work correctly. This happens when an entity falls out the entity graph because a foreign key of the entity is changed. For example, by removing a wheel from &lt;span class="codeInline"&gt;car&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; wheel = car.Wheels.First();
car.Wheels.Remove(wheel)
&lt;/pre&gt;&lt;/div&gt;Changing the foreign key forms a change of the owning entity (&lt;span class="codeInline"&gt;wheel&lt;/span&gt; in the example). But since it is no longer part of the entity graph, its change will not be submitted to the server during a partial save. The result is that after a partial save, the original context still has pending changes. It is not obvious how to deal with this. Please let me know if you have a solution.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Thu, 01 Dec 2011 09:31:00 GMT</pubDate><guid isPermaLink="false">Updated Wiki: PartialSaveWithEntityGraph 20111201093100A</guid></item><item><title>Updated Wiki: PartialSaveWithEntityGraph</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;version=8</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;How to partially save entities in your domain context?&lt;/h1&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;A RIA services domain context is used to manage your entities and to submit changes to your domain service following the unit of work pattern. The domain context gives little or no control over what entities are going to be communicated to a domain service when the &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; method is invoked. There are many situations where just submitting all pending changes is too coarse grained. In this post I will explain how EntityGraph can give control over which entities are submitted to your domain context (&lt;b&gt;but see &lt;a href="#Disclaimer"&gt;Disclaimer&lt;/a&gt; below&lt;/b&gt;).&lt;br /&gt;
&lt;h3&gt;EntityGraph in a Nutshell&lt;/h3&gt;An entity graph is defined as a collection of entities connected through their associations that forms a logical unit. An entity graph is defined by means of an entity graph shape. For example:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; shape = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraphShape()
   .Edge&amp;lt;Car, Wheel&amp;gt;(x =&amp;gt; Wheels)
   .Edge&amp;lt;Car, Engine&amp;gt;(x =&amp;gt; Engine);
&lt;/pre&gt;&lt;/div&gt;This defines the shape of an entity graph spanning the associations between &lt;span class="codeInline"&gt;Car&lt;/span&gt;, its &lt;span class="codeInline"&gt;Wheels&lt;/span&gt;, and its &lt;span class="codeInline"&gt;Engine&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Given an &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance called &lt;span class="codeInline"&gt;car&lt;/span&gt;, we can create a corresponding EntityGraph as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; graph = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraph(car, shape);
&lt;/pre&gt;&lt;/div&gt;There are many things you can now do with this entity graph. E.g., see &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs" class="externalLink"&gt;http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For partial save I&amp;#39;m going to focus on the &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. I.e., we can create a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone();
&lt;/pre&gt;&lt;/div&gt;This example creates an identical copy of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities that are reachable according to the edges in &lt;span class="codeInline"&gt;shape&lt;/span&gt; (i.e., it includes identical copies of the wheels and the engine of the car). &lt;br /&gt;
&lt;h3&gt;Implementing Partial Save&lt;/h3&gt;Lets assume that &lt;span class="codeInline"&gt;car&lt;/span&gt; is contained in the domain context &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; and that we want to submit the changes of this single &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance together with its associated wheels and engine. This basically means that we want to submit only the pending changes for the entities contained in the entity graph we just created. Of course, we can&amp;#39;t just call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; because that may also submit pending changes of entities that are not part of the graph.&lt;br /&gt;&lt;br /&gt;For a partial save of &lt;span class="codeInline"&gt;car&lt;/span&gt;, this is what we are going to do:
&lt;ol&gt;&lt;li&gt;Create a new instance of &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; called &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Duplicate the entity graph for &lt;span class="codeInline"&gt;car&lt;/span&gt; in this new context&lt;/li&gt;
&lt;li&gt;Call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;On success, synchronize the entities in the original domain context with the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;.&lt;/li&gt;&lt;/ol&gt;
A clone cannot be present in the same domain context as its source. The reason is that the cloned entities have the same primary keys. Adding them will lead to an exception indicating that an entity with the same key is already present in the context. The &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method that we used above therefore returns a cloned entity (and its associations) that is not attached to any domain context. A consequence is that the cloned entities no longer contain state information (since they are not managed by a context). They all have an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Detached&lt;/span&gt;. Attaching them to &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will give them an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;. &lt;span class="codeInline"&gt;HasChanges&lt;/span&gt; will return &lt;span class="codeInline"&gt;false&lt;/span&gt; and calling &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; will have no effect. This is clearly not what we have in mind for a partial save method.&lt;br /&gt;&lt;br /&gt;In order to make a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; that includes proper state information, the cloned entities must be attached to a domain context. For this purpose, EntityGraph also provides a state-preserving &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. It attaches the cloned entities to another context and restores the entity state. This is the method we&amp;#39;re going to use:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; partialSaveContext = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CarExampleContext();
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone(partialSaveContext);
&lt;/pre&gt;&lt;/div&gt;After calling &lt;span class="codeInline"&gt;Clone()&lt;/span&gt;, &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will contain a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities in this domain context have the same &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; as the entities in the entity graph &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This means that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;true&lt;/span&gt; and that we can now call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the context:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
partialSaveContext.SubmitChanges();
&lt;/pre&gt;&lt;/div&gt;This will submit the pending changes of the cloned entity graph rooted at &lt;span class="codeInline"&gt;car&lt;/span&gt; to the server. Nothing more, nothing less. &lt;br /&gt;&lt;br /&gt;If &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; completes without an error, you can verify that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;false&lt;/span&gt;, as expected. However, the original context still has changes pending. This can be observed by inspecting &lt;span class="codeInline"&gt;context.HasChanges&lt;/span&gt; and &lt;span class="codeInline"&gt;graph.HasChanges&lt;/span&gt;. Both properties yield &lt;span class="codeInline"&gt;true&lt;/span&gt;. This is because the source domain context still contains the original entities with their changes pending. Moreover, since we&amp;#39;ve submitted the changes to the server, some of the properties of the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; may have been updated with server-provided values (this is for instance the case with generated keys). As a final step we therefore have to synchronize the entities in the original context with the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;. This can be done with the &lt;span class="codeInline"&gt;Synchronize&lt;/span&gt; method of EntityGraph:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
graph.Synchronize(clone);
&lt;/pre&gt;&lt;/div&gt;This updates the entities in the EntityGraph &lt;span class="codeInline"&gt;graph&lt;/span&gt; according to the entities in the EntityGraph &lt;span class="codeInline"&gt;clonedGraph&lt;/span&gt;. This includes updating the entity states. As a result, &lt;span class="codeInline"&gt;graph&lt;/span&gt; and &lt;span class="codeInline"&gt;clonedGraph&lt;/span&gt; are identical clones and both have no more pending changes (you can verify that all entities in &lt;span class="codeInline"&gt;graph&lt;/span&gt; have their &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; set to &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;, exactly what is needed. This completes the partial save mechanism. Observe that &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; is no longer needed.&lt;br /&gt;&lt;a name="Disclaimer"&gt;&lt;/a&gt;
&lt;h3&gt;Disclaimer&lt;/h3&gt;There is one situation where the partial save method will/can &lt;i&gt;not&lt;/i&gt; work correctly. This happens when an entity falls out the entity graph because a foreign key of the entity is changed. For example, by removing a wheel from &lt;span class="codeInline"&gt;car&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; wheel = car.Wheels.First();
car.Wheels.Remove(wheel)
&lt;/pre&gt;&lt;/div&gt;Changing the foreign key forms a change of the owning entity (&lt;span class="codeInline"&gt;wheel&lt;/span&gt; in the example). But since it is no longer part of the entity graph, its change will not be submitted to the server during a partial save. The result is that after a partial save, the original context still has pending changes. It is not obvious how to deal with this. Please let me know if you have a solution.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Wed, 30 Nov 2011 21:09:28 GMT</pubDate><guid isPermaLink="false">Updated Wiki: PartialSaveWithEntityGraph 20111130090928P</guid></item><item><title>Updated Wiki: PartialSaveWithEntityGraph</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;version=7</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;How to partially save entities in your domain context?&lt;/h1&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;A RIA services domain context is used to manage your entities and to submit changes to your domain service following the unit of work pattern. The domain context gives little or no control over what entities are going to be communicated to a domain service when the &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; method is invoked. There are many situations where just submitting all pending changes is too coarse grained. In this post I will explain how EntityGraph can give control over which entities are submitted to your domain context (&lt;b&gt;but see &lt;a href="#Disclaimer"&gt;Disclaimer&lt;/a&gt; below&lt;/b&gt;).&lt;br /&gt;
&lt;h3&gt;EntityGraph in a Nutshell&lt;/h3&gt;An entity graph is defined as a collection of entities connected through their associations that forms a logical unit. An entity graph is defined by means of an entity graph shape. For example:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; shape = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraphShape()
   .Edge&amp;lt;Car, Wheel&amp;gt;(x =&amp;gt; Wheels)
   .Edge&amp;lt;Car, Engine&amp;gt;(x =&amp;gt; Engine);
&lt;/pre&gt;&lt;/div&gt;This defines the shape of an entity graph spanning the associations between &lt;span class="codeInline"&gt;Car&lt;/span&gt;, its &lt;span class="codeInline"&gt;Wheels&lt;/span&gt;, and its &lt;span class="codeInline"&gt;Engine&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Given an &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance called &lt;span class="codeInline"&gt;car&lt;/span&gt;, we can create a corresponding EntityGraph as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; graph = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraph(car, shape);
&lt;/pre&gt;&lt;/div&gt;There are many things you can now do with this entity graph. E.g., see &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs" class="externalLink"&gt;http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For partial save I&amp;#39;m going to focus on the &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. I.e., we can create a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone();
&lt;/pre&gt;&lt;/div&gt;This example creates an identical copy of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities that are reachable according to the edges in &lt;span class="codeInline"&gt;shape&lt;/span&gt; (i.e., it includes identical copies of the wheels and the engine of the car). &lt;br /&gt;
&lt;h3&gt;Implementing Partial Save&lt;/h3&gt;Lets assume that &lt;span class="codeInline"&gt;car&lt;/span&gt; is contained in the domain context &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; and that we want to submit the changes of this single &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance together with its associated wheels and engine. This basically means that we want to submit only the pending changes for the entities contained in the entity graph we just created. Of course, we can&amp;#39;t just call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; because that may also submit pending changes of entities that are not part of the graph.&lt;br /&gt;&lt;br /&gt;For a partial save of &lt;span class="codeInline"&gt;car&lt;/span&gt;, this is what we are going to do:
&lt;ol&gt;&lt;li&gt;Create a new instance of &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; called &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Duplicate the entity graph for &lt;span class="codeInline"&gt;car&lt;/span&gt; in this new context&lt;/li&gt;
&lt;li&gt;Call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;On success, synchronize the entities in the original domain context with the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;.&lt;/li&gt;&lt;/ol&gt;
A clone cannot be present in the same domain context as its source. The reason is that the cloned entities have the same primary keys. Adding them will lead to an exception indicating that an entity with the same key is already present in the context. The &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method that we used above therefore returns a cloned entity (and its associations) that is not attached to any domain context. A consequence is that the cloned entities no longer contain state information (since they are not managed by a context). They all have an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Detached&lt;/span&gt;. Attaching them to &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will give them an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;. &lt;span class="codeInline"&gt;HasChanges&lt;/span&gt; will return &lt;span class="codeInline"&gt;false&lt;/span&gt; and calling &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; will have no effect. This is clearly not what we have in mind for a partial save method.&lt;br /&gt;&lt;br /&gt;In order to make a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; that includes proper state information, the cloned entities must be attached to a domain context. For this purpose, EntityGraph also provides a state-preserving &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. It attaches the cloned entities to another context and restores the entity state. This is the method we&amp;#39;re going to use:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; partialSaveContext = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CarExampleContext();
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone(partialSaveContext);
&lt;/pre&gt;&lt;/div&gt;After calling &lt;span class="codeInline"&gt;Clone()&lt;/span&gt;, &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will contain a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities in this domain context have the same &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; as the entities in the entity graph &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This means that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;true&lt;/span&gt; and that we can now call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the context:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
partialSaveContext.SubmitChanges();
&lt;/pre&gt;&lt;/div&gt;This will submit the pending changes of the cloned entity graph rooted at &lt;span class="codeInline"&gt;car&lt;/span&gt; to the server. Nothing more, nothing less. &lt;br /&gt;&lt;br /&gt;If &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; completes without an error, you can verify that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;false&lt;/span&gt;, as expected. However, the original context still has changes pending. This can be observed by inspecting &lt;span class="codeInline"&gt;context.HasChanges&lt;/span&gt; and &lt;span class="codeInline"&gt;graph.HasChanges&lt;/span&gt;. Both properties yield &lt;span class="codeInline"&gt;true&lt;/span&gt;. This is because the source domain context still contains the original entities with their changes pending. Moreover, since we&amp;#39;ve submitted the changes to the server, some of the properties of the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; may have been updated with server-provided values (this is for instance the case with generated keys). As a final step we therefore have to synchronize the entities in the original context with the entities in &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;. This can be done with the &lt;span class="codeInline"&gt;Synchronize&lt;/span&gt; method of EntityGraph:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clonedGraph =  &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraph(clone, shape);
graph.Synchronize(clonedGraph);
&lt;/pre&gt;&lt;/div&gt;This updates the entities in the EntityGraph &lt;span class="codeInline"&gt;graph&lt;/span&gt; according to the entities in the EntityGraph &lt;span class="codeInline"&gt;clonedGraph&lt;/span&gt;. This includes updating the entity states. As a result, &lt;span class="codeInline"&gt;graph&lt;/span&gt; and &lt;span class="codeInline"&gt;clonedGraph&lt;/span&gt; are identical clones and both have no more pending changes (you can verify that all entities in &lt;span class="codeInline"&gt;graph&lt;/span&gt; have their &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; set to &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;, exactly what is needed. This completes the partial save mechanism. Observe that &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; is no longer needed.&lt;br /&gt;&lt;a name="Disclaimer"&gt;&lt;/a&gt;
&lt;h3&gt;Disclaimer&lt;/h3&gt;There is one situation where the partial save method will/can &lt;i&gt;not&lt;/i&gt; work correctly. This happens when an entity falls out the entity graph because a foreign key of the entity is changed. For example, by removing a wheel from &lt;span class="codeInline"&gt;car&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; wheel = car.Wheels.First();
car.Wheels.Remove(wheel)
&lt;/pre&gt;&lt;/div&gt;Changing the foreign key forms a change of the owning entity (&lt;span class="codeInline"&gt;wheel&lt;/span&gt; in the example). But since it is no longer part of the entity graph, its change will not be submitted to the server during a partial save. The result is that after a partial save, the original context still has pending changes. It is not obvious how to deal with this. Please let me know if you have a solution.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Tue, 29 Nov 2011 20:25:01 GMT</pubDate><guid isPermaLink="false">Updated Wiki: PartialSaveWithEntityGraph 20111129082501P</guid></item><item><title>New Comment on "PartialSaveWithEntityGraph"</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;ANCHOR#C21737</link><description>I thought I overlooked something, but I can&amp;#39;t find where the cloned entities had their newly updated states copied back onto the originals in the non-partial-save context&amp;#63;</description><author>joebrockhaus</author><pubDate>Mon, 28 Nov 2011 21:11:37 GMT</pubDate><guid isPermaLink="false">New Comment on "PartialSaveWithEntityGraph" 20111128091137P</guid></item><item><title>Updated Wiki: PartialSaveWithEntityGraph</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;version=6</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;How to partially save entities in your domain context?&lt;/h1&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;A RIA services domain context is used to manage your entities and to submit changes to your domain service following the unit of work pattern. The domain context gives little or no control over what entities are going to be communicated to a domain service when the &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; method is invoked. There are many situations where just submitting all pending changes is too coarse grained. In this post I will explain how EntityGraph can give control over which entities are submitted to your domain context (&lt;b&gt;but see &lt;a href="#Disclaimer"&gt;Disclaimer&lt;/a&gt; below&lt;/b&gt;).&lt;br /&gt;
&lt;h3&gt;EntityGraph in a Nutshell&lt;/h3&gt;An entity graph is defined as a collection of entities connected through their associations that forms a logical unit. An entity graph is defined by means of an entity graph shape. For example:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; shape = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraphShape()
   .Edge&amp;lt;Car, Wheel&amp;gt;(x =&amp;gt; Wheels)
   .Edge&amp;lt;Car, Engine&amp;gt;(x =&amp;gt; Engine);
&lt;/pre&gt;&lt;/div&gt;This defines the shape of an entity graph spanning the associations between &lt;span class="codeInline"&gt;Car&lt;/span&gt;, its &lt;span class="codeInline"&gt;Wheels&lt;/span&gt;, and its &lt;span class="codeInline"&gt;Engine&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Given an &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance called &lt;span class="codeInline"&gt;car&lt;/span&gt;, we can create a corresponding EntityGraph as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; graph = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraph(car, shape);
&lt;/pre&gt;&lt;/div&gt;There are many things you can now do with this entity graph. E.g., see &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs" class="externalLink"&gt;http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For partial save I&amp;#39;m going to focus on the &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. I.e., we can create a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone();
&lt;/pre&gt;&lt;/div&gt;This example creates an identical copy of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities that are reachable according to the edges in &lt;span class="codeInline"&gt;shape&lt;/span&gt; (i.e., it includes identical copies of the wheels and the engine of the car). &lt;br /&gt;
&lt;h3&gt;Implementing Partial Save&lt;/h3&gt;Lets assume that &lt;span class="codeInline"&gt;car&lt;/span&gt; is contained in the domain context &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; and that we want to submit the changes of this single &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance together with its associated wheels and engine. This basically means that we want to submit only the pending changes for the entities contained in the entity graph we just created. Of course, we can&amp;#39;t just call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; because that may also submit pending changes of entities that are not part of the graph.&lt;br /&gt;&lt;br /&gt;For a partial save of &lt;span class="codeInline"&gt;car&lt;/span&gt;, this is what we are going to do:
&lt;ol&gt;&lt;li&gt;Create a new instance of &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; called &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Duplicate the entity graph for &lt;span class="codeInline"&gt;car&lt;/span&gt; in this new context&lt;/li&gt;
&lt;li&gt;Call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;On success, accept the changes on the car entity graph in the orignal domain context.&lt;/li&gt;&lt;/ol&gt;
A clone cannot be present in the same domain context as its source. The reason is that the cloned entities have the same primary keys. Adding them will lead to an exception indicating that an entity with the same key is already present in the context. The &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method that we used above therefore returns a cloned entity (and its associations) that is not attached to any domain context. A consequence is that the cloned entities no longer contain state information (since they are not managed by a context). They all have an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Detached&lt;/span&gt;. Attaching them to &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will give them an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;. &lt;span class="codeInline"&gt;HasChanges&lt;/span&gt; will return &lt;span class="codeInline"&gt;false&lt;/span&gt; and calling &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; will have no effect. This is clearly not what we have in mind for a partial save method.&lt;br /&gt;&lt;br /&gt;In order to make a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; that includes proper state information, the cloned entities must be attached to a domain context. For this purpose, EntityGraph also provides a state-preserving &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. It attaches the cloned entities to another context and restores the entity state. This is the method we&amp;#39;re going to use:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; partialSaveContext = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CarExampleContext();
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone(partialSaveContext);
&lt;/pre&gt;&lt;/div&gt;After calling &lt;span class="codeInline"&gt;Clone()&lt;/span&gt;, &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will contain a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities in this domain context have the same &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; as the entities in the entity graph &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This means that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;true&lt;/span&gt; and that we can now call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the context:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
partialSaveContext.SubmitChanges();
&lt;/pre&gt;&lt;/div&gt;This will submit the pending changes of the cloned entity graph rooted at &lt;span class="codeInline"&gt;car&lt;/span&gt; to the server. Nothing more, nothing less. &lt;br /&gt;&lt;br /&gt;If &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; completes without an error, you can verify that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;false&lt;/span&gt;, as expected. However, the original context still has changes pending. This can be observed by inspecting &lt;span class="codeInline"&gt;context.HasChanges&lt;/span&gt; and &lt;span class="codeInline"&gt;graph.HasChanges&lt;/span&gt;. Both properties yield &lt;span class="codeInline"&gt;true&lt;/span&gt;. This is because the source domain context still contains the original entities with their changes pending. Since we&amp;#39;ve submitted the changes to the server, we should, as a final step, instruct &lt;span class="codeInline"&gt;context&lt;/span&gt; to just accept the pending changes on the entities in &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This can be done using the &lt;span class="codeInline"&gt;System.ComponentModel.IChangeTracking&lt;/span&gt; interface that is defined on entities and on entity graphs:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
graph.AcceptChanges()
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will set the &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of all entities in our entity graph to &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;, exactly what is needed. This completes the partial save mechanism. Observe that &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; is no longer needed.&lt;br /&gt;&lt;a name="Disclaimer"&gt;&lt;/a&gt;
&lt;h3&gt;Disclaimer&lt;/h3&gt;There is one situation where the partial save method will/can &lt;i&gt;not&lt;/i&gt; work correctly. This happens when an entity falls out the entity graph because a foreign key of the entity is changed. For example, by removing a wheel from &lt;span class="codeInline"&gt;car&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; wheel = car.Wheels.First();
car.Wheels.Remove(wheel)
&lt;/pre&gt;&lt;/div&gt;Changing the foreign key forms a change of the owning entity (&lt;span class="codeInline"&gt;wheel&lt;/span&gt; in the example). But since it is no longer part of the entity graph, its change will not be submitted to the server during a partial save. The result is that after a partial save, the original context still has pending changes. It is not obvious how to deal with this. Please let me know if you have a solution.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Mon, 28 Nov 2011 16:48:48 GMT</pubDate><guid isPermaLink="false">Updated Wiki: PartialSaveWithEntityGraph 20111128044848P</guid></item><item><title>Updated Wiki: PartialSaveWithEntityGraph</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;version=5</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;How to partially save entities in your domain context?&lt;/h1&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;A RIA services domain context is used to manage your entities and to submit changes to your domain service following the unit of work pattern. The domain context gives little or no control over what entities are going to be communicated to a domain service when the &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; method is invoked. There are many situations where just submitting all pending changes is too coarse grained. In this post I will explain how EntityGraph can give control over which entities are submitted to your domain context (&lt;b&gt;but see &lt;a href="#Disclaimer"&gt;Disclaimer&lt;/a&gt; below&lt;/b&gt;).&lt;br /&gt;
&lt;h3&gt;EntityGraph in a Nutshell&lt;/h3&gt;An entity graph is defined as a collection of entities connected through their associations that forms a logical unit. An entity graph is defined by means of an entity graph shape. For example:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; shape = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraphShape()
   .Edge&amp;lt;Car, Wheel&amp;gt;(x =&amp;gt; Wheels)
   .Edge&amp;lt;Car, Engine&amp;gt;(x =&amp;gt; Engine);
&lt;/pre&gt;&lt;/div&gt;This defines the shape of an entity graph spanning the associations between &lt;span class="codeInline"&gt;Car&lt;/span&gt;, its &lt;span class="codeInline"&gt;Wheels&lt;/span&gt;, and its &lt;span class="codeInline"&gt;Engine&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Given an &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance called &lt;span class="codeInline"&gt;car&lt;/span&gt;, we can create a corresponding EntityGraph as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; graph = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraph(car, shape);
&lt;/pre&gt;&lt;/div&gt;There are many things you can now do with this entity graph. E.g., see &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs" class="externalLink"&gt;http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For partial save I&amp;#39;m going to focus on the &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. I.e., we can create a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone();
&lt;/pre&gt;&lt;/div&gt;This example creates an identical copy of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities that are reachable according to the edges in &lt;span class="codeInline"&gt;shape&lt;/span&gt; (i.e., it includes identical copies of the wheels and the engine of the car). &lt;br /&gt;
&lt;h3&gt;Implementing Partial Save&lt;/h3&gt;Lets assume that &lt;span class="codeInline"&gt;car&lt;/span&gt; is contained in the domain context &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; and that we want to submit the changes of this single &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance together with its associated wheels and engine. This basically means that we want to submit only the pending changes for the entities contained in the entity graph we just created. Of course, we can&amp;#39;t just call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; because that may also submit pending changes of entities that are not part of the graph.&lt;br /&gt;&lt;br /&gt;For a partial save of &lt;span class="codeInline"&gt;car&lt;/span&gt;, this is what we are going to do:
&lt;ol&gt;&lt;li&gt;Create a new instance of &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; called &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Duplicate the entity graph for &lt;span class="codeInline"&gt;ar&lt;/span&gt; in this new context&lt;/li&gt;
&lt;li&gt;Call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;On success, accept the changes on the car entity graph in the orignal domain context.&lt;/li&gt;&lt;/ol&gt;
A clone cannot be present in the same domain context as its source. The reason is that the cloned entities have the same primary keys. Adding them will lead to an exception indicating that an entity with the same key is already present in the context. The &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method that we used above therefore returns a cloned entity (and its associations) that is not attached to any domain context. A consequence is that the cloned entities no longer contain state information (since they are not managed by a context). They all have an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Detached&lt;/span&gt;. Attaching them to &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will give them an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;. &lt;span class="codeInline"&gt;HasChanges&lt;/span&gt; will return &lt;span class="codeInline"&gt;false&lt;/span&gt; and calling &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; will have no effect. This is clearly not what we have in mind for a partial save method.&lt;br /&gt;&lt;br /&gt;In order to make a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; that includes proper state information, the cloned entities must be attached to a domain context. For this purpose, EntityGraph also provides a state-preserving &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. It attaches the cloned entities to another context and restores the entity state. This is the method we&amp;#39;re going to use:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; partialSaveContext = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CarExampleContext();
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone(partialSaveContext);
&lt;/pre&gt;&lt;/div&gt;After calling &lt;span class="codeInline"&gt;Clone()&lt;/span&gt;, &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will contain a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities in this domain context have the same &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; as the entities in the entity graph &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This means that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;true&lt;/span&gt; and that we can now call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the context:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
partialSaveContext.SubmitChanges();
&lt;/pre&gt;&lt;/div&gt;This will submit the pending changes of the cloned entity graph rooted at &lt;span class="codeInline"&gt;car&lt;/span&gt; to the server. Nothing more, nothing less. &lt;br /&gt;&lt;br /&gt;If &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; completes without an error, you can verify that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;false&lt;/span&gt;, as expected. However, the original context still has changes pending. This can be observed by inspecting &lt;span class="codeInline"&gt;context.HasChanges&lt;/span&gt; and &lt;span class="codeInline"&gt;graph.HasChanges&lt;/span&gt;. Both properties yield &lt;span class="codeInline"&gt;true&lt;/span&gt;. This is because the source domain context still contains the original entities with their changes pending. Since we&amp;#39;ve submitted the changes to the server, we should, as a final step, instruct &lt;span class="codeInline"&gt;context&lt;/span&gt; to just accept the pending changes on the entities in &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This can be done using the &lt;span class="codeInline"&gt;System.ComponentModel.IChangeTracking&lt;/span&gt; interface that is defined on entities and on entity graphs:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
graph.AcceptChanges()
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will set the &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of all entities in our entity graph to &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;, exactly what is needed. This completes the partial save mechanism. Observe that &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; is no longer needed.&lt;br /&gt;&lt;a name="Disclaimer"&gt;&lt;/a&gt;
&lt;h3&gt;Disclaimer&lt;/h3&gt;There is one situation where the partial save method will/can &lt;i&gt;not&lt;/i&gt; work correctly. This happens when an entity falls out the entity graph because a foreign key of the entity is changed. For example, by removing a wheel from &lt;span class="codeInline"&gt;car&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; wheel = car.Wheels.First();
car.Wheels.Remove(wheel)
&lt;/pre&gt;&lt;/div&gt;Changing the foreign key forms a change of the owning entity (&lt;span class="codeInline"&gt;wheel&lt;/span&gt; in the example). But since it is no longer part of the entity graph, its change will not be submitted to the server during a partial save. The result is that after a partial save, the original context still has pending changes. It is not obvious how to deal with this. Please let me know if you have a solution.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Mon, 28 Nov 2011 16:42:38 GMT</pubDate><guid isPermaLink="false">Updated Wiki: PartialSaveWithEntityGraph 20111128044238P</guid></item><item><title>Updated Wiki: PartialSaveWithEntityGraph</title><link>http://riaservicescontrib.codeplex.com/wikipage?title=PartialSaveWithEntityGraph&amp;version=4</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;How to partially save entities in your domain context?&lt;/h1&gt;
&lt;br /&gt;A RIA services domain context is used to manage your entities and to submit changes to your domain service following the unit of work pattern. The domain context gives little or no control over what entities are going to be communicated to a domain service when the &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; method is invoked. There are many situations where just submitting all pending changes is too coarse grained. In this post I will explain how EntityGraph can give control over which entities are submitted to your domain context (&lt;b&gt;but see &lt;a href="#Disclaimer"&gt;Disclaimer&lt;/a&gt; below&lt;/b&gt;).&lt;br /&gt;&lt;br /&gt;An entity graph is defined as a collection of entities connected through their associations that forms a logical unit. An entity graph is defined by means of an entity graph shape. For example:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; shape = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraphShape()
   .Edge&amp;lt;Car, Wheel&amp;gt;(x =&amp;gt; Wheels)
   .Edge&amp;lt;Car, Engine&amp;gt;(x =&amp;gt; Engine);
&lt;/pre&gt;&lt;/div&gt;This defines the shape of an entity graph spanning the associations between &lt;span class="codeInline"&gt;Car&lt;/span&gt;, its &lt;span class="codeInline"&gt;Wheels&lt;/span&gt;, and its &lt;span class="codeInline"&gt;Engine&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Given an &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance called &lt;span class="codeInline"&gt;car&lt;/span&gt;, we can create a corresponding EntityGraph as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; graph = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; EntityGraph(car, shape);
&lt;/pre&gt;&lt;/div&gt;There are many things you can now do with this entity graph. E.g., see &lt;a href="http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs" class="externalLink"&gt;http://riaservicescontrib.codeplex.com/wikipage?title=EntityGraphs&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For partial save I&amp;#39;m going to focus on the &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. I.e., we can create a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone();
&lt;/pre&gt;&lt;/div&gt;This example creates an identical copy of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities that are reachable according to the edges in &lt;span class="codeInline"&gt;shape&lt;/span&gt; (i.e., it includes identical copies of the wheels and the engine of the car). &lt;br /&gt;&lt;br /&gt;Lets assume that &lt;span class="codeInline"&gt;car&lt;/span&gt; is contained in the domain context &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; and that we want to submit the changes of this single &lt;span class="codeInline"&gt;Car&lt;/span&gt; instance together with its associated wheels and engine. This basically means that we want to submit only the pending changes for the entities contained in the entity graph we just created. Of course, we can&amp;#39;t just call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; because that may also submit pending changes of entities that are not part of the graph.&lt;br /&gt;&lt;br /&gt;For a partial save of &lt;span class="codeInline"&gt;car&lt;/span&gt;, this is what we are going to do:
&lt;ol&gt;&lt;li&gt;Create a new instance of &lt;span class="codeInline"&gt;CarExampleContext&lt;/span&gt; called &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Duplicate the entity graph for &lt;span class="codeInline"&gt;ar&lt;/span&gt; in this new context&lt;/li&gt;
&lt;li&gt;Call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;On success, accept the changes on the car entity graph in the orignal domain context.&lt;/li&gt;&lt;/ol&gt;
A clone cannot be present in the same domain context as its source. The reason is that the cloned entities have the same primary keys. Adding them will lead to an exception indicating that an entity with the same key is already present in the context. The &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method that we used above therefore returns a cloned entity (and its associations) that is not attached to any domain context. A consequence is that the cloned entities no longer contain state information (since they are not managed by a context). They all have an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Detached&lt;/span&gt;. Attaching them to &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will give them an &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;. &lt;span class="codeInline"&gt;HasChanges&lt;/span&gt; will return &lt;span class="codeInline"&gt;false&lt;/span&gt; and calling &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; will have no effect. This is clearly not what we have in mind for a partial save method.&lt;br /&gt;&lt;br /&gt;In order to make a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; that includes proper state information, the cloned entities must be attached to a domain context. For this purpose, EntityGraph also provides a state-preserving &lt;span class="codeInline"&gt;Clone()&lt;/span&gt; method. It attaches the cloned entities to another context and restores the entity state. This is the method we&amp;#39;re going to use:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; partialSaveContext = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; CarExampleContext();
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = graph.Clone(partialSaveContext);
&lt;/pre&gt;&lt;/div&gt;After calling &lt;span class="codeInline"&gt;Clone()&lt;/span&gt;, &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; will contain a clone of &lt;span class="codeInline"&gt;car&lt;/span&gt; and all entities in this domain context have the same &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; as the entities in the entity graph &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This means that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;true&lt;/span&gt; and that we can now call &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; on the context:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
partialSaveContext.SubmitChanges();
&lt;/pre&gt;&lt;/div&gt;This will submit the pending changes of the cloned entity graph rooted at &lt;span class="codeInline"&gt;car&lt;/span&gt; to the server. Nothing more, nothing less. &lt;br /&gt;&lt;br /&gt;If &lt;span class="codeInline"&gt;SubmitChanges()&lt;/span&gt; completes without an error, you can verify that &lt;span class="codeInline"&gt;partialSaveContext.HasChanges&lt;/span&gt; yields &lt;span class="codeInline"&gt;false&lt;/span&gt;, as expected. However, the original context still has changes pending. This can be observed by inspecting &lt;span class="codeInline"&gt;context.HasChanges&lt;/span&gt; and &lt;span class="codeInline"&gt;graph.HasChanges&lt;/span&gt;. Both properties yield &lt;span class="codeInline"&gt;true&lt;/span&gt;. This is because the source domain context still contains the original entities with their changes pending. Since we&amp;#39;ve submitted the changes to the server, we should, as a final step, instruct &lt;span class="codeInline"&gt;context&lt;/span&gt; to just accept the pending changes on the entities in &lt;span class="codeInline"&gt;graph&lt;/span&gt;. This can be done using the &lt;span class="codeInline"&gt;System.ComponentModel.IChangeTracking&lt;/span&gt; interface that is defined on entities and on entity graphs:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
graph.AcceptChanges()
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;This will set the &lt;span class="codeInline"&gt;EntityState&lt;/span&gt; of all entities in our entity graph to &lt;span class="codeInline"&gt;EntityState.Unmodified&lt;/span&gt;, exactly what is needed. This completes the partial save mechanism. Observe that &lt;span class="codeInline"&gt;partialSaveContext&lt;/span&gt; is no longer needed.&lt;br /&gt;&lt;a name="Disclaimer"&gt;&lt;/a&gt;
&lt;h2&gt;Disclaimer&lt;/h2&gt;There is one situation where the partial save method will/can &lt;i&gt;not&lt;/i&gt; work correctly. This happens when an entity falls out the entity graph because a foreign key of the entity is changed. For example, by removing a wheel from &lt;span class="codeInline"&gt;car&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; wheel = car.Wheels.First();
car.Wheels.Remove(wheel)
&lt;/pre&gt;&lt;/div&gt;Changing the foreign key forms a change of the owning entity (&lt;span class="codeInline"&gt;wheel&lt;/span&gt; in the example). But since it is no longer part of the entity graph, its change will not be submitted to the server during a partial save. The result is that after a partial save, the original context still has pending changes. It is not obvious how to deal with this. Please let me know if you have a solution.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>MdeJ</author><pubDate>Mon, 28 Nov 2011 16:39:45 GMT</pubDate><guid isPermaLink="false">Updated Wiki: PartialSaveWithEntityGraph 20111128043945P</guid></item></channel></rss>