<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Digital Ruminations</title><subtitle type="html">Discourses on divers matters related to computers and their programming, lead by your humble host Mathew Charles.</subtitle><id>http://blogs.msdn.com/digital_ruminations/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/digital_ruminations/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2006-02-13T19:11:00Z</updated><entry><title>EF v2 Goodness + RIA Services</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2009/11/19/ef-v2-goodness-ria-services.aspx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2009/11/19/ef-v2-goodness-ria-services.aspx</id><published>2009-11-19T18:44:17Z</published><updated>2009-11-19T18:44:17Z</updated><content type="html">&lt;p&gt;If you’ve spent any time on the RIA Services forums or attempting to use our &lt;strong&gt;LinqToEntitiesDomainService&lt;/strong&gt; base class yourself, you’ll know that it wasn’t very hard to run into issues :) For example, it was very easy to run into server side issues when processing more complicated graph updates. As I have explained many times in the forums, all of these issues were caused by the fact that EF v1 really didn’t support N-Tier so in our domain layer, we were doing our best to mask that via some non-trivial workarounds. Our team has been in close contact with the EF team over the last year discussing these limitations, and the great news is that in EF v2, they’ve &lt;u&gt;vastly improved&lt;/u&gt; the N-Tier support (see the MSDN topic &lt;a href="http://msdn.microsoft.com/en-us/library/bb896304(VS.100).aspx"&gt;N-Tier Applications With Entity Framework&lt;/a&gt; for details) in .NET 4.0. With this new support, we’ve been able to completely overhaul our EF provider. These changes are transparent to you, their main impact being that you should no longer run into any of the previous issues that have plagued the provider. Our &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=RiaServices&amp;amp;DownloadId=8313"&gt;breaking changes document&lt;/a&gt; describes two changes that were required for us to make these improvements, but I’ll summarize those here:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Only EF models that include FK info are supported&lt;/strong&gt; – This is the new 4.0 default when creating an EF model, so we’re just lining up our story with that. What this allowed us to do was remove all the dynamic TypeDescriptor stuff we were required to do before to manufacture FK members dynamically from the EF model. This was a bug factory.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/digital_ruminations/WindowsLiveWriter/40cff9c45c8b_905F/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/digital_ruminations/WindowsLiveWriter/40cff9c45c8b_905F/image_thumb_4.png" width="376" height="168" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Only EF models that embed their mapping info as a resource are supported&lt;/strong&gt; – This is important for partial trust scenarios where we shouldn’t be attempting to load EF mapping files from disk. Again this is the EF default.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/digital_ruminations/WindowsLiveWriter/40cff9c45c8b_905F/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/digital_ruminations/WindowsLiveWriter/40cff9c45c8b_905F/image_thumb_3.png" width="379" height="198" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As I mentioned, the changes to our provider were mainly behind the scenes, save for one change to wizard codegen. The Insert method we generate now uses the new ObjectStateManager.ChangeObjectState API:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InsertProduct(Product product)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ((product.EntityState != EntityState.Added))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ((product.EntityState != EntityState.Detached))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ObjectContext.ObjectStateManager&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;                 .ChangeObjectState(product, EntityState.Added);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ObjectContext.AddToProducts(product);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In summary, what all this means for me, is a big sigh of relief, since I was the author and maintainer of our EF provider, and had the unfortunate task of answering for all the issues people encountered. It also means I don’t have to spend time in the forums explaining esoteric EF issues and providing workarounds :) What this means for you is a vastly improved EF experience in RIA Services :)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9925649" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author><category term="RIA Services" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/RIA+Services/default.aspx" /></entry><entry><title>Composition Support in RIA Services</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2009/11/18/composition-support-in-ria-services.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="27685" href="http://blogs.msdn.com/digital_ruminations/attachment/9924163.ashx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2009/11/18/composition-support-in-ria-services.aspx</id><published>2009-11-18T08:27:00Z</published><updated>2009-11-18T08:27:00Z</updated><content type="html">&lt;p&gt;I’m having a great time at &lt;a href="http://microsoftpdc.com/"&gt;PDC 2009&lt;/a&gt; talking to customers about Silverlight and RIA Services. The second keynote just finished, Scott unveiled SL4 which means now our team can talk about our PDC Beta of RIA Services for VS 2008 / SL3 as well as our preview for VS 2010 / SL4! You can download the new bits from our &lt;a href="http://www.silverlight.net/getstarted/riaservices/"&gt;WCF RIA Services&lt;/a&gt; landing site.&lt;/p&gt;  &lt;p&gt;Between sessions, I've found time to make the first of a series of posts on the new features and work we’ve done in this release. In this post I’ll discuss the support we’ve added to RIA Services for &lt;strong&gt;compositional relationships&lt;/strong&gt;. Lets jump right in :) A compositional relationship has the following characteristics:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;the lifetime of the child of the association is governed by the parent &lt;/li&gt;    &lt;li&gt;the parent and its children are treated as a single unit &lt;/li&gt;    &lt;li&gt;children have no identity/existence independent of their parent &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The classic PurchaseOrder/OrderDetails association has these characteristics and is often modeled as a composition. A detail cannot exist independent of its parent and generally when operating on an order it and all its details are viewed together and operated upon / validated together. In contrast, the Employee / Reports association is not a compositional – reporting employees exist independent of their manager, meaning if the manager is fired, the reports are hopefully re-parented :)&lt;/p&gt;  &lt;p&gt;To facilitate application models that include compositional relationships, we’ve introduced &lt;strong&gt;CompositionAttribute&lt;/strong&gt; which can be used to mark an association as a composition. Of course you can have compositional hierarchies of arbitrary depth. Compositions in RIA Services gain the following behaviors:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Hierarchical change tracking – when a child entity is modified, it’s parent also transitions to the Modified state. &lt;/li&gt;    &lt;li&gt;When a parent is in the Modified state, &lt;u&gt;all&lt;/u&gt; of its children are included in the change-set sent to the server, including any Unmodified children. &lt;/li&gt;    &lt;li&gt;Operation ordering – Often only CRUD operations for the parent or root type in a compositional hierarchy will be exposed by a DomainService. This allows you to write all your business logic for a hierarchy in a single method. However writing explicit methods for child Types is supported, in which case parent operations are always called before child operations. For example, if a new OrderDetail was added to an existing PurchaseOrder, the Update method for PurchaseOrder would be called before the Insert for the OrderDetail. &lt;/li&gt;    &lt;li&gt;Public EntitySets for child Types are not generated on the code-genned DomainContext. Children are only accessible via their parent relationship. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Simply marking an association with the attribute enables all this functionality automatically for the association:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PurchaseOrderMetadata&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     [Include]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     [Composition]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; EntitySet&amp;lt;OrderDetail&amp;gt; OrderDetails;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;In addition to this new attribute there are a few new server side APIs to help with compositions. These new APIs are shown below in a hierarchical update method that takes a PurchaseOrder / OrderDetail compositional hierarchy and controls the update for the entire hierarchy:&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdateOrder(PurchaseOrder order)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     PurchaseOrder origOrder = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ChangeSet.GetOriginal(order);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (origOrder != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContext.PurchaseOrders.Attach(order, origOrder);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContext.PurchaseOrders.Attach(order);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (OrderDetail detail &lt;span style="color: #0000ff"&gt;in&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;       &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ChangeSet.GetAssociatedChanges(order, p =&amp;gt; p.OrderDetails))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;         ChangeOperation op = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ChangeSet.GetChangeOperation(detail);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (op)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ChangeOperation.Insert:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContext.OrderDetails.InsertOnSubmit(detail);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ChangeOperation.Update:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContext.OrderDetails.Attach(detail, &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum24"&gt;  24:&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ChangeSet.GetOriginal(detail));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum25"&gt;  25:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum26"&gt;  26:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; ChangeOperation.Delete:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum27"&gt;  27:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContext.OrderDetails.Attach(detail);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum28"&gt;  28:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContext.OrderDetails.DeleteOnSubmit(detail);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum29"&gt;  29:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum30"&gt;  30:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;default&lt;/span&gt;:&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum31"&gt;  31:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum32"&gt;  32:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum33"&gt;  33:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum34"&gt;  34:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;The new APIs shown above are:&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;ChangeSet.GetAssociatedChanges&lt;/strong&gt; – given a parent object and an association, this method returns all child objects in the change-set for that association. You could simply enumerate PurchaseOrder.OrderDetails directly, but of course that wouldn’t include deleted Details. The helper method returns those as well. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;ChangeSet.GetChangeOperation&lt;/strong&gt; – for a specified object, returns a ChangeOperation enum value indicating whether the object operation is Insert, Update, Delete, or None (unmodified). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This post has been a quick introduction to the feature. Attached is a zipped project containing a fully functional composition sample (VS 2010). The solution includes a detailed readme which walks you through the details of the sample and demonstrates the feature in more depth. Now I’m going to go down to the Silverlight booth to chat with more users :)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9924163" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author><category term="RIA Services" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/RIA+Services/default.aspx" /></entry><entry><title>.NET RIA Services July CTP</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2009/07/10/net-ria-services-july-ctp.aspx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2009/07/10/net-ria-services-july-ctp.aspx</id><published>2009-07-10T20:51:00Z</published><updated>2009-07-10T20:51:00Z</updated><content type="html">&lt;P&gt;After much work, our team &lt;A href="http://silverlight.net/forums/t/108916.aspx" target=_blank mce_href="http://silverlight.net/forums/t/108916.aspx"&gt;just released the July CTP of .NET RIA Services&lt;/A&gt;. We're releasing this CTP in step&amp;nbsp;with the big Silverlight 3 release, as trumpeted on &lt;A href="http://weblogs.asp.net/scottgu/archive/2009/07/10/silverlight-3-released.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/archive/2009/07/10/silverlight-3-released.aspx"&gt;ScottGu's SL3 blog post here&lt;/A&gt;. As mentioned in Scott's post, "&lt;EM&gt;&lt;STRONG&gt;The new .NET RIA Services framework (which now has a go-live license) can be used to easily build multi-tier data applications that span the client and server.&lt;/STRONG&gt;&lt;/EM&gt;" If you're interested in building rich multi-tier Silverlight applications you should check out the framework we're building. Some relevant links:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en" target=_blank mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en"&gt;Install the .NET RIA Services July CTP&lt;/A&gt;&amp;nbsp;- From this link you can download the overview doc which describes the framework, as well as install the latest bits.&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://silverlight.net/forums/53.aspx" target=_blank mce_href="http://silverlight.net/forums/53.aspx"&gt;.NET RIA Services project forum&lt;/A&gt; - an active forum where our current CTP users discuss issues&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://code.msdn.microsoft.com/RiaServices" target=_blank mce_href="http://code.msdn.microsoft.com/RiaServices"&gt;.NET RIA Services samples&lt;/A&gt; - a place where our team uploads sample applications, and other types of samples for the framework&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;My intention going forward is to use this blog to explain framework features, discuss design points for new and existing features, as well as to share sample code.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9828962" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author><category term="RIA Services" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/RIA+Services/default.aspx" /></entry><entry><title>Devs Writing Haiku?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2007/08/30/devs-writing-haiku.aspx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2007/08/30/devs-writing-haiku.aspx</id><published>2007-08-30T23:11:00Z</published><updated>2007-08-30T23:11:00Z</updated><content type="html">&lt;p&gt;A while back&amp;nbsp;Jomo Fisher on our team&amp;nbsp;started a rather&amp;nbsp;interesting tradition.&amp;nbsp; It&amp;nbsp;all began one day after he had sent out a code-review to the team but after some time had heard no response.&amp;nbsp; Being the impatient guy that he is,&amp;nbsp;he decided to prod his colleagues with a little poetry, resending the request with the following haiku added:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000a0"&gt;Spring’s warmth melts snow while&lt;br&gt;nearby code awaits review.&lt;br&gt;Sweet check-in beckons.&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This beautiful haiku had the desired effect -&amp;nbsp;his code was reviewed promptly!&amp;nbsp; With this success, a tradition was born of &lt;u&gt;threatening with haiku&lt;/u&gt; if code review requests were ignored for too long. Other devs on the team began crafting their own haiku, hoping to&amp;nbsp;expedite &lt;em&gt;their&lt;/em&gt; reviews as well.&amp;nbsp; Here's a few I've sent out:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000a0"&gt;Code review ignored&lt;br&gt;Changeset languishing unseen&lt;br&gt;Evening approaches&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000a0"&gt;Unreviewed change-set&lt;br&gt;Like an unharvested fruit&lt;br&gt;Dying on the vine &lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000a0"&gt;Devs writing haiku&lt;br&gt;Idly waiting to check in&lt;br&gt;Orcas slowly slips&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Here's one from Matt Warren&amp;nbsp;after a completed&amp;nbsp;code review:  &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000a0"&gt;Code reviewed okay&lt;br&gt;Some shenanigans undone&lt;br&gt;Quality improves&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;From haiku, things have started snowballing into other verse forms.&amp;nbsp; Here's a great one by Keith Farmer in response to an email set out by Luca Bolognese after the C# PM team hit their ZBB (zero bug bounce) milestone:  &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000a0"&gt;To Xen PU did LucaBol&lt;br&gt;An email send, full of glee:&lt;br&gt;Tests finally ran,&lt;br&gt;Past bugs measureless to man,&lt;br&gt;Down to a ZBB.&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I'll have to hunt around my mail folders for the rest, I know there are some I've missed.&amp;nbsp;Recently Jomo suggested that&amp;nbsp;haiku are going out of style and that he preferred limmericks.&amp;nbsp; We'll have to see where that goes ...&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4653741" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author></entry><entry><title>Linq To Sql POCO Support</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2007/08/28/linq-to-sql-poco-support.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="960687" href="http://blogs.msdn.com/digital_ruminations/attachment/4616377.ashx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2007/08/28/linq-to-sql-poco-support.aspx</id><published>2007-08-28T21:22:00Z</published><updated>2007-08-28T21:22:00Z</updated><content type="html">&lt;P&gt;A&amp;nbsp;colleague and I were recently discussing POCO support in Linq To Sql (LTS), and he pointed me to a &lt;A href="http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!397.entry" mce_href="http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!397.entry"&gt;great blog post by Ian Cooper&lt;/A&gt;&amp;nbsp;on Domain v.s. Data Centric design methodologies and how Linq To Sql can be used for domain centric development.&amp;nbsp; As Ian points out, LTS places very little requirements on domain classes,&amp;nbsp;allowing them to remain "persistence ignorant".&amp;nbsp; For example, we don't require any particular base class or interface, no particular constructors are required (except the default), &lt;U&gt;no special types are required for association members&lt;/U&gt;, etc.&amp;nbsp;&amp;nbsp;I don't believe the last point is widely known which is why I decided to make this post.&amp;nbsp; The EntitySet&amp;lt;T&amp;gt;/EntityRef&amp;lt;T&amp;gt; classes that we codegen by default for associations are not required.&amp;nbsp; In POCO scenarios you can map your association members to either List&amp;lt;T&amp;gt; or T[] like so (see the attached project for complete sources):&lt;/P&gt;&lt;PRE class=code&gt;    &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Customer
&lt;/SPAN&gt;    {
        &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Order&lt;/SPAN&gt;&amp;gt; _Orders;&lt;/PRE&gt;&lt;PRE class=code&gt;        &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Order&lt;/SPAN&gt;&amp;gt; Orders {
            &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;get&lt;/SPAN&gt; {
                &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;this&lt;/SPAN&gt;._Orders;
            }
            &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;set&lt;/SPAN&gt; {
                &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;this&lt;/SPAN&gt;._Orders = &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;value&lt;/SPAN&gt;;
            }
        }
    }&lt;/PRE&gt;
&lt;P&gt;Assuming this member is mapped&amp;nbsp;as an association&amp;nbsp;in your external mapping file, LTS will treat it as&amp;nbsp;such.&amp;nbsp; Likewise, instead of EntityRef&amp;lt;T&amp;gt; for singleton associations, you will just type your member as T.&amp;nbsp; Of course now that you're not using our association types, one of the things you lose is support for deferred loading.&amp;nbsp; Normally during materialization Linq To Sql assigns deferred sources to your EntitySets/EntityRefs which upon enumeration result in the deferred source query being compiled and executed.&amp;nbsp; In the case of POCO associations you'll have to explicitly specify the span to eager load - by default no associations will be loaded:&lt;/P&gt;&lt;PRE class=code&gt;     &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Northwind&lt;/SPAN&gt; nw = &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Northwind&lt;/SPAN&gt;(&lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"Northwind.sdf"&lt;/SPAN&gt;);

     &lt;SPAN style="COLOR: rgb(0,128,0)"&gt;// Load Customer, specifying span
&lt;/SPAN&gt;     DataLoadOptions ds = &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;new&lt;/SPAN&gt; DataLoadOptions();
     ds.LoadWith&amp;lt;&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Customer&lt;/SPAN&gt;&amp;gt;(p =&amp;gt; p.Orders);
     ds.LoadWith&amp;lt;&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Order&lt;/SPAN&gt;&amp;gt;(p =&amp;gt; p.OrderDetails);
     ds.AssociateWith&amp;lt;&lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Customer&lt;/SPAN&gt;&amp;gt;(p =&amp;gt; p.Orders.Where(o =&amp;gt; o.Freight &amp;gt; 20));
     nw.LoadOptions = ds;
     &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Customer&lt;/SPAN&gt; cust = nw.Customers.Where(p =&amp;gt; p.City == &lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"London"&lt;/SPAN&gt;).First();&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;With the DataLoadOptions set for preloading, the materializer compiles the appropriate member query, executing it with the correct FK arguments for each row materialized.&amp;nbsp; In this example, the returned customer has all of it's Orders with a Freight &amp;gt; 20 preloaded, and all OrderDetails for each Order are also preloaded.&lt;/P&gt;
&lt;P&gt;There are some other Linq To Sql features that are useful from a domain driven design perspective.&amp;nbsp; For example, DataContext exposes &lt;STRONG&gt;CreateDatabase&lt;/STRONG&gt; functionality allowing you to&amp;nbsp;generate a database&amp;nbsp;from your domain model (expressed as a DataContext of POCO entities), as opposed to the normal method of using SqlMetal or the LTS Designer to generate full featured entities from your database (Data Centric).&amp;nbsp; When coupled with our support for SqlCE, this is a very convenient feature:&lt;/P&gt;&lt;PRE class=code&gt;     &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Northwind&lt;/SPAN&gt; nw = &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Northwind&lt;/SPAN&gt;(&lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"NewNorthwind.sdf"&lt;/SPAN&gt;);
     &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;if&lt;/SPAN&gt; (!nw.DatabaseExists()) {
          nw.CreateDatabase();
     }
     &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Customer&lt;/SPAN&gt; cust = &lt;SPAN style="COLOR: rgb(0,0,255)"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: rgb(43,145,175)"&gt;Customer&lt;/SPAN&gt; { CustomerID = &lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"MATHC"&lt;/SPAN&gt;, CompanyName = &lt;SPAN style="COLOR: rgb(163,21,21)"&gt;"Microsoft"&lt;/SPAN&gt; };
     nw.Customers.Add(cust);
     nw.SubmitChanges();&lt;/PRE&gt;
&lt;P&gt;One other final note on POCO -&amp;nbsp; as you'll notice, entities code genned by SqlMetal implement &lt;STRONG&gt;INotifyPropertyChanging&lt;/STRONG&gt;.&amp;nbsp; As stated above this is not required, but it does allow our change tracker to be more efficient in it's copying of original values.&amp;nbsp; For classes implementing this interface the change tracker subscribes to the PropertyChanging event, allowing us to&amp;nbsp;put off copying original values until the object has actually changed.&amp;nbsp; Otherwise we have no choice but to copy the values immediately on materialization/attach.&lt;/P&gt;
&lt;P&gt;In summary, Linq To Sql offers very good support for POCO classes, providing framework services to your objects in a non-invasive, loosely coupled manner.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4616377" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author><category term="POCO" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/POCO/default.aspx" /><category term="Linq To Sql" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/Linq+To+Sql/default.aspx" /></entry><entry><title>C# LINQ to SQL Chat</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2006/12/13/c-linq-to-sql-chat.aspx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2006/12/13/c-linq-to-sql-chat.aspx</id><published>2006-12-14T00:23:00Z</published><updated>2006-12-14T00:23:00Z</updated><content type="html">&lt;P&gt;We just had another community chat yesterday on Linq to Sql (aka DLinq) - you can access a copy of&amp;nbsp;the transcript here: &lt;A href="http://blogs.msdn.com/charlie/archive/2006/12/13/c-linq-to-sql-chat-dec-12-2006.aspx" mce_href="http://blogs.msdn.com/charlie/archive/2006/12/13/c-linq-to-sql-chat-dec-12-2006.aspx"&gt;http://blogs.msdn.com/charlie/archive/2006/12/13/c-linq-to-sql-chat-dec-12-2006.aspx&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;We had a good turnout and&amp;nbsp;got a lot of great questions and feedback - it's great to see that people are excited about this exciting technology :)&amp;nbsp; On the Linq to Sql team we just finished up a several month&amp;nbsp;coding milestone - we've implemented some new cool new features and also polished up the existing code, fixed bugs, etc.&amp;nbsp; The fruits of this labor will be available in the February 2007 Orcas CTP.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1277896" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author><category term="DLinq" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/DLinq/default.aspx" /><category term="Linq To Sql" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/Linq+To+Sql/default.aspx" /></entry><entry><title>DLinq User-Defined Function support</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2006/06/13/dlinq-user-defined-function-support.aspx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2006/06/13/dlinq-user-defined-function-support.aspx</id><published>2006-06-13T08:19:00Z</published><updated>2006-06-13T08:19:00Z</updated><content type="html">&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;em&gt;[Updated on 8/30/2007: Code samples below updated for Beta2.&amp;nbsp; The main thing we did was simplify the code required by providing framework methods ExecuteMethodCall/CreateMethodCallQuery that create the required expression trees (where you had to create them before). You'll also notice that there is a single mapping attribute for both sprocs and functions, with IsComposible being used to distinguish between the two.]&lt;/em&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;In the last post, we looked at DLinq Stored Procedure support.&amp;nbsp; Another cool new DLinq feature in the latest LINQ preview is support for &lt;u&gt;user-defined functions&lt;/u&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;We’ve added support for mapping methods to user-defined functions (both scalar and table-valued) allowing the UDFs to be used in queries naturally.&lt;span style="color: black"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;You can run SqlMetal from a VS command prompt against the Northwind database specifying the &lt;b style="mso-bidi-font-weight: normal"&gt;/functions&lt;/b&gt; option to generate mapped methods for user-defined functions:&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="font-size: 10pt"&gt;C:\Program Files\Microsoft Visual Studio 9.0\VC&amp;gt;sqlmetal /server:localhost &lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="font-size: 10pt"&gt;/database:"Northwind" &lt;/span&gt;&lt;span style="font-size: 10pt"&gt;/namespace:nwind /code:northwind.cs /language:csharp &lt;b style="mso-bidi-font-weight: normal"&gt;/functions&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;If you take a look at the generated code you’ll see that methods have been added to the Northwind data context that map to the user-defined functions in the database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;An excerpt is shown below:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;partial&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Northwind&lt;/span&gt; : DataContext {
    . . .
    [Function(Name = &lt;span style="color: rgb(163,21,21)"&gt;"dbo.TotalProductUnitPriceByCategory"&lt;/span&gt;, IsComposable = &lt;span style="color: rgb(0,0,255)"&gt;true&lt;/span&gt;)]
    [&lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt;: Parameter(&lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt; = &lt;span style="color: rgb(163,21,21)"&gt;"Money"&lt;/span&gt;)]
    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; System.&lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0,0,255)"&gt;decimal&lt;/span&gt;&amp;gt; TotalProductUnitPriceByCategory(
                   [Parameter(&lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt; = &lt;span style="color: rgb(163,21,21)"&gt;"Int"&lt;/span&gt;)] System.&lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;&amp;gt; categoryID) {
        &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; ((System.&lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0,0,255)"&gt;decimal&lt;/span&gt;&amp;gt;)
               (&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;.ExecuteMethodCall(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, 
               ((&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;)(&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod())), 
               categoryID).ReturnValue));
    }

    [Function(Name=&lt;span style="color: rgb(163,21,21)"&gt;"dbo.ProductsUnderThisUnitPrice"&lt;/span&gt;, IsComposable=&lt;span style="color: rgb(0,0,255)"&gt;true&lt;/span&gt;)]
    &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;ProductsUnderThisUnitPriceResult&lt;/span&gt;&amp;gt; ProductsUnderThisUnitPrice(
                   [Parameter(&lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt;=&lt;span style="color: rgb(163,21,21)"&gt;"Money"&lt;/span&gt;)] System.&lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0,0,255)"&gt;decimal&lt;/span&gt;&amp;gt; price) {
        &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;.CreateMethodCallQuery&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;ProductsUnderThisUnitPriceResult&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, 
               ((&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;)(&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod())), price);
    }
    . . .
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;In the method bodies for these UDF mapped methods, you see that we call the ExecuteMethodCall context method to&amp;nbsp;create the required expression tree, execute the query and return the result. When the method is used &lt;u&gt;inline in a query&lt;/u&gt; this code is not executed – the query translator knows how to translate the method based on metadata (attribute or external).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;However if the method called &lt;u&gt;outside of a query&lt;/u&gt; then the method body is executed to create the method call expression, turn it into a query and execute it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The first UDF ‘TotalProductUnitPriceByCategory’ takes a category ID and returns the total of all unit prices for products in that category.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Here is an example using this function in a query:&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;       var&lt;/span&gt; q = &lt;span style="color: rgb(0,0,255)"&gt;from&lt;/span&gt; c &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; db.Categories
               &lt;span style="color: rgb(0,0,255)"&gt;select&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; {
                 c.CategoryName,
                 Total = db.TotalProductUnitPriceByCategory(c.CategoryID)
               };&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The function is used inline in a query just like you use a UDF inline in a SQL query.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Below is the SQL that is generated – the UDF call is translated as you would expect:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="font-size: 10pt"&gt;SELECT [t0].[CategoryID], &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; text-indent: 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="font-size: 10pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;[dbo].[TotalProductUnitPriceByCategory]([t0].[CategoryID])&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt"&gt; AS [value]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="font-size: 10pt"&gt;FROM [Categories] AS [t0]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;If the same UDF is executed &lt;i style="mso-bidi-font-style: normal"&gt;outside&lt;/i&gt; of a query the mapped method builds the expression and creates and executes a query:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;      decimal&lt;/span&gt; total = db.TotalProductUnitPriceByCategory(8);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;SELECT &lt;b style="mso-bidi-font-weight: normal"&gt;[dbo].[TotalProductUnitPriceByCategory](@p0)&lt;/b&gt; AS [value]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;The ‘ProductsUnderThisUnitPrice’ method is mapped to a table valued UDF, and returns an IQueryable.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;As such, it can be used in a query wherever a table or sub-query can be.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Here is an example joining a table to the results of a TVF (and the resulting SQL):&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;      var&lt;/span&gt; q = &lt;span style="color: rgb(0,0,255)"&gt;from&lt;/span&gt; c &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; db.Categories
              &lt;span style="color: rgb(0,0,255)"&gt;from&lt;/span&gt; p &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; db.ProductsUnderThisUnitPrice(8.50M)
              &lt;span style="color: rgb(0,0,255)"&gt;where&lt;/span&gt; c.CategoryID == p.CategoryID
              &lt;span style="color: rgb(0,0,255)"&gt;select&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; {
                    c.CategoryID,
                    c.CategoryName,
                    p.ProductName,
                    p.UnitPrice
              };&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;SELECT [t0].[CategoryID], [t0].[CategoryName],&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [t1].[ProductName], [t1].[UnitPrice]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;FROM [Categories] AS [t0]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;CROSS JOIN &lt;b style="mso-bidi-font-weight: normal"&gt;[dbo].[ProductsUnderThisUnitPrice](@p0)&lt;/b&gt; AS [t1]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'"&gt;WHERE [t0].[CategoryID] = [t1].[CategoryID]&lt;/span&gt;&lt;span style="font-size: 10pt; color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;As a final example let’s look at how to map &lt;b style="mso-bidi-font-weight: normal"&gt;system functions&lt;/b&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;While DLinq automatically maps many .NET methods (like string/DateTime methods) to corresponding system functions, there may be some system functions that have no .NET counterpart that you’d like to use.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In such cases, you can map a method yourself.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;For example, if you’re just dying to be able to use the SqlServer Soundex function directly in your DLinq queries, you can map it as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="code"&gt;     [&lt;span style="color: rgb(43,145,175)"&gt;Function&lt;/span&gt;(Name = &lt;span style="color: rgb(163,21,21)"&gt;"Soundex"&lt;/span&gt;, IsComposable = &lt;span style="color: rgb(0,0,255)"&gt;true&lt;/span&gt;)]
     &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; SoundEx([&lt;span style="color: rgb(43,145,175)"&gt;Parameter&lt;/span&gt;(Name = &lt;span style="color: rgb(163,21,21)"&gt;"Expression"&lt;/span&gt;)] &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; expression) {
         &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; (&lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt;)&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;.ExecuteMethodCall(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, 
                ((&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;)(&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod())), 
                 expression).ReturnValue;
     }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;This function can now be used as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;     var&lt;/span&gt; q = &lt;span style="color: rgb(0,0,255)"&gt;from&lt;/span&gt; e &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; db.Employees
             &lt;span style="color: rgb(0,0,255)"&gt;orderby&lt;/span&gt; db.Soundex(e.FirstName)
             &lt;span style="color: rgb(0,0,255)"&gt;select&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; {
                 e.FirstName, 
                 Soundex=db.Soundex(e.FirstName)
             };
     &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; s = db.Soundex(&lt;span style="color: rgb(163,21,21)"&gt;"Mathew Charles"&lt;/span&gt;);&lt;/pre&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;If you use UDFs in your database and are playing around with the new CTP, give them a try in your DLinq queries and please let us know what you think!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=629121" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author></entry><entry><title>Spring Linq CTP finally hits the shelves!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2006/05/11/spring-linq-ctp-finally-hits-the-shelves.aspx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2006/05/11/spring-linq-ctp-finally-hits-the-shelves.aspx</id><published>2006-05-11T02:14:00Z</published><updated>2006-05-11T02:14:00Z</updated><content type="html">&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;em&gt;[Updated on 8/30/2007: Code samples below updated for Beta2.&amp;nbsp; The main thing we did was simplify the code required by providing framework methods ExecuteMethodCall that creates the required expression trees (where you had to create them before). You'll also notice that there is a single mapping attribute for both sprocs and functions, with IsComposible being used to distinguish between the two.]&lt;/em&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;The latest and greatest LINQ preview has finally been released! (you can download here: &lt;a href="http://msdn.microsoft.com/netframework/future/" mce_href="http://msdn.microsoft.com/netframework/future/"&gt;http://msdn.microsoft.com/netframework/future/&lt;/a&gt;)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;In addition to fixing a lot of bugs since the last CTP and making additions and modifications based on community feedback, we’ve also added some cool new features.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I’d like to use the next few posts to explore a sampling of some of these new features (you can read about more of them in the C# readme &lt;a href="http://msdn.microsoft.com/netframework/future/linqcsharpreadme/" mce_href="http://msdn.microsoft.com/netframework/future/linqcsharpreadme/"&gt;here&lt;/a&gt;).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The topic for today:&lt;/span&gt; &lt;u&gt;Stored-Procedure Support&lt;/u&gt;.&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;We’ve added support for mapping methods to stored procedures allowing you to invoke them in a strongly typed manner as methods on the DataContext.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;To see this in action, you can run SqlMetal against the Northwind sample database specifying the &lt;b style="mso-bidi-font-weight: normal"&gt;/sprocs&lt;/b&gt; option to generate mapped methods for stored-procedures:&amp;nbsp;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&amp;nbsp;C:\Program Files\Microsoft Visual Studio 9.0\VC&amp;gt;sqlmetal /server:localhost &lt;br&gt;/database:"Northwind" /namespace:nwind /code:northwind.cs /language:csharp &lt;strong&gt;/sprocs&lt;/strong&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;If you take a look at the generated code, you’ll see that methods have been added to the Northwind data context that map to the stored procedures in the database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;An excerpt is shown below.&amp;nbsp; The [Parameter] attributes aren't strictly necessary if your method parameters have the same names as the sproc params in the database, and explicit type mapping is not needed, but I've included them for completeness.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;    public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;partial&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Northwind&lt;/span&gt; : DataContext {
        . . .
        [Function(Name=&lt;span style="color: rgb(163,21,21)"&gt;"dbo.CustOrderTotal"&lt;/span&gt;)]
        [&lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt;: Parameter(&lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt;=&lt;span style="color: rgb(163,21,21)"&gt;"Int"&lt;/span&gt;)]
        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt; CustOrderTotal(
            [Parameter(Name=&lt;span style="color: rgb(163,21,21)"&gt;"CustomerID"&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt;=&lt;span style="color: rgb(163,21,21)"&gt;"NChar(5)"&lt;/span&gt;)] &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; customerID, 
            [Parameter(Name=&lt;span style="color: rgb(163,21,21)"&gt;"TotalSales"&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt;=&lt;span style="color: rgb(163,21,21)"&gt;"Money"&lt;/span&gt;)] &lt;span style="color: rgb(0,0,255)"&gt;ref&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0,0,255)"&gt;decimal&lt;/span&gt;&amp;gt; totalSales)
        {
            IExecuteResult result = &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;.ExecuteMethodCall(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, 
                ((&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;)(&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod())), customerID, totalSales);
            totalSales = ((System.&lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0,0,255)"&gt;decimal&lt;/span&gt;&amp;gt;)(result.GetParameterValue(1)));
            &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; ((&lt;span style="color: rgb(0,0,255)"&gt;int&lt;/span&gt;)(result.ReturnValue));
        }

        [Function(Name=&lt;span style="color: rgb(163,21,21)"&gt;"dbo.Sales by Year"&lt;/span&gt;)]
        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; ISingleResult&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;SalesByYearResult&lt;/span&gt;&amp;gt; SalesByYear(
            [Parameter(Name=&lt;span style="color: rgb(163,21,21)"&gt;"Beginning_Date"&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt;=&lt;span style="color: rgb(163,21,21)"&gt;"DateTime"&lt;/span&gt;)] 
                &lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;&amp;gt; beginning_Date, 
            [Parameter(Name=&lt;span style="color: rgb(163,21,21)"&gt;"Ending_Date"&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt;=&lt;span style="color: rgb(163,21,21)"&gt;"DateTime"&lt;/span&gt;)] 
                &lt;span style="color: rgb(43,145,175)"&gt;Nullable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;&amp;gt; ending_Date)
        {
            IExecuteResult result = &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;.ExecuteMethodCall(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, 
                ((&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;)(&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod())), beginning_Date, ending_Date);
            &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; ((ISingleResult&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;SalesByYearResult&lt;/span&gt;&amp;gt;)(result.ReturnValue));
        }

        [Function(Name=&lt;span style="color: rgb(163,21,21)"&gt;"dbo.Get Customer And Orders"&lt;/span&gt;)]
        [ResultType(&lt;span style="color: rgb(0,0,255)"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43,145,175)"&gt;GetCustomerAndOrdersResult1&lt;/span&gt;))]
        [ResultType(&lt;span style="color: rgb(0,0,255)"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43,145,175)"&gt;GetCustomerAndOrdersResult2&lt;/span&gt;))]
        &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; IMultipleResults GetCustomerAndOrders(
            [Parameter(Name=&lt;span style="color: rgb(163,21,21)"&gt;"CustomerID"&lt;/span&gt;, &lt;span style="color: rgb(43,145,175)"&gt;DbType&lt;/span&gt;=&lt;span style="color: rgb(163,21,21)"&gt;"NChar(5)"&lt;/span&gt;)] &lt;span style="color: rgb(0,0,255)"&gt;string&lt;/span&gt; customerID)
        {
            IExecuteResult result = &lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;.ExecuteMethodCall(&lt;span style="color: rgb(0,0,255)"&gt;this&lt;/span&gt;, 
                ((&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;)(&lt;span style="color: rgb(43,145,175)"&gt;MethodInfo&lt;/span&gt;.GetCurrentMethod())), customerID);
            &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; ((IMultipleResults)(result.ReturnValue));
        }
        . . .
    }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The ‘CustOrderTotal’ method is mapped to a simple &lt;u&gt;scalar sproc&lt;/u&gt; that takes an input parameter and returns an output parameter.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Here’s how you would call it (all samples below assume a Northwind context instance ‘db’):&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;    decimal&lt;/span&gt;? totalSales = 0;
    db.CustOrderTotal(&lt;span style="color: rgb(163,21,21)"&gt;"ALFKI"&lt;/span&gt;, &lt;span style="color: rgb(0,0,255)"&gt;ref&lt;/span&gt; totalSales);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;The ‘SalesByYear’ method demonstrates how a &lt;u&gt;rowset returning sproc&lt;/u&gt; is mapped.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;For sprocs returning rowsets, a class is automatically generated for the rowset.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Here is how you would call this sproc and access its result set:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(43,145,175)"&gt;    DateTime&lt;/span&gt; begin = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;(1996, 11, 5);
    &lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt; end = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;(1997, 3, 15);
    &lt;span style="color: rgb(43,145,175)"&gt;ISingleResult&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;SalesByYearResult&lt;/span&gt;&amp;gt; sales = db.SalesByYear(begin, end);
    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; bigSales = sales.Where(s =&amp;gt; s.Subtotal &amp;gt; 5000.00m);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Important points to note here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; color: black; font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;The return type &lt;span style="color: rgb(43,145,175)"&gt;ISingleResult&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;SalesByYearResult&lt;/span&gt;&amp;gt; implements &lt;span style="font-size: 10pt; color: teal; font-family: 'Courier New'; mso-no-proof: yes"&gt;IEnumerable &lt;/span&gt;allowing the returned rows to be enumerated,&amp;nbsp;and also allows the sproc return value to be accessed if needed (via &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;the ReturnValue property).&lt;/div&gt;
&lt;li&gt;
&lt;div class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; color: black; font-family: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"&gt;&lt;span style="mso-list: ignore"&gt;&lt;span style="font: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;In cases where a sproc returns both a result set AND an out parameter, all results are read and buffered automatically (triggered by the first out parameter access) prior to the mapped method returning, since reading all the results off the wire is the only way to get the out parameter values.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Finally the ‘GetCustomerAndOrders’ method shows how &lt;u&gt;sprocs that return multiple result-sets&lt;/u&gt; are mapped.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;From the database metadata, we can determine what possible rowset shapes can be returned from the sproc, but not in what order.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Thus it is up to you to request the results in the correct order, as shown below:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(43,145,175)"&gt;    IMultipleResults&lt;/span&gt; results = db.GetCustomerAndOrders(&lt;span style="color: rgb(163,21,21)"&gt;"ALFKI"&lt;/span&gt;);
    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; cust = results.GetResult&amp;lt;GetCustomerAndOrdersResult1&amp;gt;().First();
    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; orders = results.GetResult&amp;lt;GetCustomerAndOrdersResult2&amp;gt;().ToArray();&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;If you are hand mapping sproc methods you'll likely want to use names more appropriate than Result1, Result2, etc.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; Using the DLinq designer, you can map your sprocs manually and&amp;nbsp;&lt;/span&gt;rename things appropriately.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You might also want to map the results to existing types (i.e. use Customers and Orders in the last example). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;Note there are some limitations to the types of sprocs we can automatically generate code for.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;For example, the following categories of sprocs cannot be auto generated:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul style="margin-top: 0in" type="disc"&gt;
&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; color: black; mso-list: l0 level1 lfo2; tab-stops: list .5in"&gt;&lt;u&gt;&lt;span style="color: windowtext"&gt;Sprocs using temporary tables&lt;/span&gt;&lt;/u&gt;&lt;span style="color: windowtext"&gt; – Since using FMTONLY true when executing a sproc (the mechanism we use to determine result shapes) doesn’t execute any statements, any CREATE TABLE statements used in a sproc to create a temporary table will not be executed.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;This means that if the sproc returns a result set formed by querying such a temporary table, any attempt to get the metadata will fail, since the table doesn’t exist&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt; 
&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; color: black; mso-list: l0 level1 lfo2; tab-stops: list .5in"&gt;&lt;u&gt;&lt;span style="color: windowtext"&gt;Sprocs using dynamic SQL to return result sets&lt;/span&gt;&lt;/u&gt;&lt;span style="color: windowtext"&gt; – If a sproc contains conditional logic that is used to build a dynamic SQL statement, then execute it to return a result set, there is no way to get metadata for the result set, since the query used to generate it can be variable, and is only known at runtime.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;If you have sprocs that fall into these categories, SqlMetal will skip generation for them and log an error message.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Of course you have the option of hand mapping them yourself.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: black"&gt;As you can see such method mapping makes stored procedures convenient to call, by encapsulating the invocation as a simple method call, and providing data binding.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The SampleQueries project (LINQ Preview\Samples\C#\SampleQueries) includes some additional sproc samples.&amp;nbsp; Give them a try, and please let us know what you think!&amp;nbsp; Next post we'll take a look at DLinq support for &lt;strong&gt;User-Defined Functions&lt;/strong&gt; (UDFs), and see how you can use them inline in your queries.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 12pt; color: black; font-family: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=594951" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author><category term="DLinq" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/DLinq/default.aspx" /><category term="Linq To Sql" scheme="http://blogs.msdn.com/digital_ruminations/archive/tags/Linq+To+Sql/default.aspx" /></entry><entry><title>Genesis...</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/digital_ruminations/archive/2006/02/13/531119.aspx" /><id>http://blogs.msdn.com/digital_ruminations/archive/2006/02/13/531119.aspx</id><published>2006-02-13T22:11:00Z</published><updated>2006-02-13T22:11:00Z</updated><content type="html">&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;As a first post, I'll introduce myself, and state briefly my intention for this blog going forward.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I've been a software engineer at Microsoft for four years.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I spent the last 3+ years working on a project named MBF (&lt;A href="http://www.channelweb.com/article/showArticle.jhtml;jsessionid=L4UUL4Z05LMF4QSNDBECKHSCJUMEKJVN?articleId=18841267&amp;amp;_requestid=224794"&gt;Microsoft Business Framework&lt;/A&gt;), but sadly that project was &lt;A href="http://www.crn.com/sections/breakingnews/dailyarchives.jhtml?articleId=172302546"&gt;recently disbanded&lt;/A&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;I'm now on the CSharp team working on the exciting new &lt;A href="http://msdn.microsoft.com/netframework/future/linq/"&gt;Linq/DLinq&lt;/A&gt; project.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In the future, expect this blog to contain fascinating, action packed posts related to Linq/DLinq specifically, as well as interesting posts on the wonderful art of Software Engineering in general.&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=531119" width="1" height="1"&gt;</content><author><name>mathewc</name><uri>http://blogs.msdn.com/members/mathewc.aspx</uri></author></entry></feed>