<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Dinesh's Cyberstation</title><link>http://blogs.msdn.com/dinesh.kulkarni/default.aspx</link><description /><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>.NET RIA Services Resources (for March 2009 Preview)</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2009/03/26/net-ria-services-resource-for-march-2009-preview.aspx</link><pubDate>Fri, 27 Mar 2009 02:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9512357</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/9512357.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=9512357</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=9512357</wfw:comment><description>&lt;p&gt;Some of it is covered in my previous post and on Silverlight.net but here is a summary:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Bits (prereq: Visual Studio 2008 SP1, &lt;a href="http://silverlight.net/getstarted/silverlight3/default.aspx"&gt;Silverlight 3 beta&lt;/a&gt; tools for VS): &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en"&gt;RIA Services March Preview&lt;/a&gt; (unveiled last week at MIX)&lt;/li&gt; &lt;li&gt;Documentation / video&lt;/li&gt; &lt;ol&gt; &lt;li&gt;A PDF file with an intro and quick starts is &lt;a href="http://go.microsoft.com/fwlink/?LinkID=144687"&gt;here&lt;/a&gt;&lt;/li&gt; &lt;li&gt;If you have an hour or so, you could try the walkthrough in the RIA Services March Preview MSI&lt;/li&gt;&lt;/ol&gt; &lt;li&gt;MIX talks - videos&lt;/li&gt; &lt;ol&gt; &lt;li&gt;RIA Services + Client &lt;a href="http://videos.visitmix.com/MIX09/T40F" target="_blank"&gt;Overview&lt;/a&gt; (BradA)&lt;/li&gt; &lt;li&gt;RIA Services &lt;a href="http://videos.visitmix.com/MIX09/T41F" target="_blank"&gt;Deep Dive&lt;/a&gt; (NikhilKo) &lt;/li&gt;&lt;/ol&gt; &lt;li&gt;Samples: &lt;a href="http://code.msdn.microsoft.com/RiaServices"&gt;http://code.msdn.microsoft.com/RiaServices&lt;/a&gt;&lt;/li&gt; &lt;li&gt;Questions, comments, bug reports, feedback: &lt;a href="http://silverlight.net/forums/53.aspx" target="_blank"&gt;.NET RIA Services Forum&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Common questions and quick answers: &lt;p&gt;How is this related to ADO.NET Data Services (Astoria)? &lt;br&gt;We have a plan to give you the best of both the worlds in forthcoming CTPs. You can see slide #19 in Pablo's talk for an outline. (The March preview does not use Astoria) &lt;p&gt;Do I have to use LINQ to SQL or EF?&lt;br&gt;No you do not. You can just use DomainService base class. In fact when you access web services or XML file or some other non-ORM source, it makes sense to just write your class to derive from DomainService. For other ORMs, we are working with a few community members to get provider stories worked out. We also hope to publish a provider sample to help out. &lt;p&gt;Do I have to use Silverlight?&lt;br&gt;No you don't have to (though I hope you at least try it out). While we have a great story with Silverlight beta, you could also use RIA Services in a web app with a few early preview bits of ASP.NET DomainDataSource. There is also an SEO story. In future, we hope to bring you AJAX, publishing as a web service etc. &lt;p&gt;What is the Silverlight 3.0 RTM story? &lt;br&gt;We are planning to release an updated CTP in the Silverlight 3.0 RTM timeframe to integrate with Silverlight 3.0. We would like to release go-live CTPs later in the year before an RTW (date TBD). &lt;p&gt;Are you feature-complete? Are there more goodies coming?&lt;br&gt;There is more stuff to come. So send you feedback in - on forum or one of the team member blogs. So fire away.  &lt;p&gt;What features are you considering?&lt;br&gt;That is a good topic for future blog/forum posts. I have to think about getting the candidate feature list in a reasonable shape with good description so you can give some feedback. &lt;p&gt;I tried running this on &amp;lt;blah&amp;gt; with &amp;lt;foo&amp;gt; turned on and &amp;lt;bar&amp;gt; off and &amp;lt;baz&amp;gt; showed up? Is this expected?&lt;br&gt;You bet that's by design :-). That aside, this sounds like a great question to ask on the &lt;a href="http://silverlight.net/forums/53.aspx"&gt;forum&lt;/a&gt; where people are trying out all kinds of things way beyond the capability and imagination of the little team that built RIA Services preview (and certainly beyond my very limited knowledge).  &lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9512357" width="1" height="1"&gt;</description></item><item><title>.NET RIA Services is now public</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2009/03/18/net-ria-services-is-now-public.aspx</link><pubDate>Wed, 18 Mar 2009 21:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9487638</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/9487638.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=9487638</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=9487638</wfw:comment><description>&lt;p&gt;A few folks have asked me what I have been up to after wrapping up LINQ previews and V1. I have not been able to answer that question satisfactorily because what we were working on was non-public (well almost except the mention of now obsolete name "Alexandria" at PDC 2008).&lt;/p&gt; &lt;p&gt;Few other folks have wondered aloud if I was deaf to their feedback about the importance of multi-tier support in LINQ to SQL (and similar projects). I was not deaf but I couldn't answer that question satisfactorily either.&lt;/p&gt; &lt;p&gt;Now I can answer both by pointing to a real preview; not just blah blah.&lt;/p&gt; &lt;p&gt;Take a look at the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en"&gt;.NET RIA Services March 2009 preview&lt;/a&gt;. It is intended to:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Simplify n-tier development (and really show you a better way to get multi-tier story for your ORM objects - LINQ to SQL or EF or whatever)  &lt;li&gt;Support Rich Internet Application (RIA) development on Silverlight - there is great end-to-end story for validation, authentication, easy databinding etc.  &lt;li&gt;Extend your ASP.NET development experience. This is based on what you know and use already. There is even an ASP.NET DomainDataSource and templates for SEO there (and hopefully some AJAX stuff soon - fingers crossed).&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Personally another satisfying thing is that, now I can answer your questions in a straightforward fashion without worrying about what I am allowed to say.&lt;/p&gt; &lt;p&gt;BTW, in the good tradition of the LINQ project, we also have a great walkthrough in the MSI and a good set of &lt;a href="http://download.microsoft.com/download/F/B/8/FB8CA635-296B-487F-965C-8148F08B5319/riaservicesoverviewpreview.pdf" mce_href="http://download.microsoft.com/download/F/B/8/FB8CA635-296B-487F-965C-8148F08B5319/riaservicesoverviewpreview.pdf"&gt;quick starts&lt;/a&gt; on the download page.&lt;/p&gt; &lt;p&gt;Don't forget to see &lt;a href="http://blogs.msdn.com/brada/" mce_href="http://blogs.msdn.com/brada/"&gt;Brad&lt;/a&gt;'s and &lt;a href="http://www.nikhilk.net/" mce_href="http://www.nikhilk.net/"&gt;Nikhil&lt;/a&gt;'s sessions at &lt;a href="http://live.visitmix.com/" mce_href="http://live.visitmix.com/"&gt;MIX&lt;/a&gt; - either live or after the fact.&lt;/p&gt; &lt;p&gt;Dinesh&lt;/p&gt; &lt;p&gt;P.S. (Thu 3/19 update): We also have some &lt;a href="http://code.msdn.microsoft.com/RiaServices"&gt;cool additional code&lt;/a&gt; for you. There is a new project template that missed the March 09 preview train by a hair - it makes authentication hookup really simple. Two sample apps make it easier for you to build good looking apps with real data hookup on the server-side. I would urge you to actually go through the walkthrough steps first and not use the newly posted, completed solution ;-)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9487638" width="1" height="1"&gt;</description></item><item><title>"Essential LINQ" book to be published tomorrow</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2009/03/10/essential-linq-book-to-be-published-tomorrow.aspx</link><pubDate>Wed, 11 Mar 2009 08:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9470136</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/9470136.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=9470136</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=9470136</wfw:comment><description>&lt;p&gt;I have been underground for a while - trying to wrap up the LINQ book and working on some exciting stuff for Silverlight. For the latter, my lips are sealed until Mix 209. For the former, it is a different story ...&lt;/p&gt; &lt;p&gt;Last month, I finally finished all the prep work and so did my co-author Charlie Calvert. My editors from Addison Wesley tell me that the book is going to be out tomorrow. Here is the &lt;a href="http://www.informit.com/store/product.aspx?isbn=0321564162" mce_href="http://www.informit.com/store/product.aspx?isbn=0321564162"&gt;ToC&lt;/a&gt;&amp;nbsp; and here is the &lt;a href="http://www.amazon.com/Essential-LINQ-Microsoft-NET-Development/dp/0321564162/"&gt;Amazon&lt;/a&gt; listing. I am also adding the ToC to this post.&lt;/p&gt; &lt;p&gt;After Mix, I will have a lot more to say about how we are taking steps in the next interesting area - beyond DALs but I will keep quiet lest I divulge more than I am allowed to.&lt;/p&gt; &lt;p mce_keep="true"&gt;Dinesh&lt;/p&gt; &lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt; &lt;p mce_keep="true"&gt;&lt;a href="http://www.amazon.com/Essential-LINQ-Microsoft-NET-Development/dp/0321564162/"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="EssentialLINQ" src="http://blogs.msdn.com/blogfiles/dinesh.kulkarni/WindowsLiveWriter/EssentialLINQbooktobepublishedtomorrow_F9E7/EssentialLINQ_3.jpg" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p mce_keep="true"&gt;&lt;b&gt;&lt;span style="font-size: 13pt; font-family: 'Arial','sans-serif'"&gt;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/p&gt; &lt;p mce_keep="true"&gt;&lt;b&gt;&lt;span style="font-size: 13pt; font-family: 'Arial','sans-serif'"&gt;Table of Contents&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;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;i&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Foreword&amp;nbsp; xxi&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;i&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Acknowledgments&amp;nbsp; xxv&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;i&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;About the Authors&amp;nbsp; xxix&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Introduction&amp;nbsp; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Getting Started&amp;nbsp; 13&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The Essence of LINQ&amp;nbsp; 39&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C# 3.0 Technical Overview&amp;nbsp; 65&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Writing Query Expressions&amp;nbsp; 129&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Query Operators&amp;nbsp; 175&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A Quick Tour of LINQ to SQL&amp;nbsp; 231&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Reading Objects with LINQ to SQL&amp;nbsp; 247&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Modifying Objects with LINQ to SQL&amp;nbsp; 281&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using Stored Procedures and Database Functions with LINQ to SQL&amp;nbsp; 319&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Customizing Entity Persistence and Adding Business Logic&amp;nbsp; 337&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LINQ to Entities Overview&amp;nbsp; 349&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LINQ to XML: Creation&amp;nbsp; 369&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Querying and Editing XML&amp;nbsp; 387&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XML Namespaces, Transforms, and Schema Validation&amp;nbsp; 423&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Introduction to LINQ Patterns and Practices&amp;nbsp; 465&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 17&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LINQ Everywhere&amp;nbsp; 487&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Chapter 18&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Conclusion&amp;nbsp; 515&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Appendix A&amp;nbsp;&amp;nbsp;&amp;nbsp; Tips for Developers&amp;nbsp; 519&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 18pt"&gt;&lt;span style="font-size: 9.5pt; font-family: 'Arial','sans-serif'"&gt;Index&amp;nbsp; 547&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p mce_keep="true"&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9470136" width="1" height="1"&gt;</description></item><item><title>.NET Framework 3.5 SP1: LINQ perf improvements (LINQ to Objects and LINQ to SQL)</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/08/10/net-fx-3-5-sp1-two-perf-improvements-linq-to-objects-and-linq-to-sql.aspx</link><pubDate>Mon, 11 Aug 2008 08:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8847562</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8847562.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8847562</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8847562</wfw:comment><description>&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;There are three perf improvements in the just released &lt;SPAN style="COLOR: windowtext; TEXT-DECORATION: none; text-underline: none"&gt;&lt;A href="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx" mce_href="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx"&gt;SP1&lt;/A&gt;&lt;/SPAN&gt;. As always, I will let you run your own microbenchmarks or more meaningful app-level benchmarks.&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="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;STRONG&gt;LINQ to Objects: &lt;/STRONG&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: 'Arial','sans-serif'"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Specialized enumerable: The new implementation recognizes queries that apply Where and/or Select to arrays or List&amp;lt;T&amp;gt;s and fold pipelines of multiple enumerable objects into single specialized enumerables. This produces substantial improvement in base overhead of common LINQ to Objects queries (at times 30+%).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;Cast&amp;lt;T&amp;gt; breaking change: This is a bug fix and a breaking change (see &lt;A href="http://blogs.msdn.com/ed_maurer/archive/2008/02/16/breaking-change-in-linq-queries-using-explicitly-typed-range-variables.aspx" mce_href="http://blogs.msdn.com/ed_maurer/archive/2008/02/16/breaking-change-in-linq-queries-using-explicitly-typed-range-variables.aspx"&gt;this&lt;/A&gt; post for background). The intended use of the NET FX 3.5 Cast&amp;lt;T&amp;gt; extension method is querying over non-generic collection types, whose elements require either a reference conversion or an unboxing step to be used in a generic query context. A late change VS 2008 cycle allowed the cast to succeed in more situations than intended, such as converting float values to int, where it should instead be throwing an InvalidCastException. The breaking change reverts the beta2 behavior and improves perf by simplifying the implementation of CastIterator&amp;lt;T&amp;gt;. Value conversions and explicitly-defined user conversions cause an &lt;B&gt;InvalidCastException&lt;/B&gt; instead of being allowed (as in RTM).&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; stringList = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArrayList&lt;/SPAN&gt; { &lt;SPAN style="COLOR: #a31515"&gt;"foo"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"bar"&lt;/SPAN&gt; };&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; intList = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArrayList&lt;/SPAN&gt; { 3, 4, 5 };&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; strings = &lt;SPAN style="COLOR: blue"&gt;from&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; s &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; stringList&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt; s;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; ints = &lt;SPAN style="COLOR: blue"&gt;from&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; i &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; intList&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt; i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;The above queries compile to &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; strings = stringList.Cast&amp;lt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&amp;gt;();&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;var&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; ints = intList.Cast&amp;lt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;&amp;gt;();&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;You can imagine a simplified implementation&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Console'"&gt;static&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;T&amp;gt; CastIterator&amp;lt;T&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt; source)&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;{&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; obj &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; source) &lt;SPAN style="COLOR: blue"&gt;yield&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; (T)obj;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;A href="http://11011.net/software/vspaste" mce_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: 'Arial','sans-serif'"&gt;&lt;STRONG&gt;LINQ to SQL: &lt;/STRONG&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: 'Arial','sans-serif'"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;This too is a bug fix. The original intent was to optimize id-based queries that are expected to return singletons. If an entity with a matching key value is already in the DataContext identity cache, then translating the query to SQL and executing it against the database is a pure waste of time since the retrieved row is promptly thrown away to avoid stomping on user's existing object. Now that bug has been fixed. So an id-based query will not cause a trip to the database. This results in a dramatic perf improvement (one hash table lookup instead of SQL translation + SQL query execution) in an admittedly narrow but common scenario.&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;BR&gt;BTW, as mentioned in a previous post, I haven't worked on either component for SP1. But I have been deeply involved in them for 3.5 RTM so I can't resist tracking such sweet changes. Besides, I am working on a &lt;A class="" href="http://www.informit.com/authors/bio.aspx?a=cf8c0e31-2c75-4e3b-8079-06bc394eb839" mce_href="http://www.informit.com/authors/bio.aspx?a=cf8c0e31-2c75-4e3b-8079-06bc394eb839"&gt;LINQ book&lt;/A&gt; that keeps me very involved with the components.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Dinesh&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8847562" width="1" height="1"&gt;</description></item><item><title>Templated code gen for LINQ to SQL</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/08/07/templated-code-gen-for-linq-to-sql.aspx</link><pubDate>Fri, 08 Aug 2008 07:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8842356</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8842356.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8842356</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8842356</wfw:comment><description>&lt;P&gt;This is going to be a brief one. If you are using LINQ to SQL, you should check out Damien's new &lt;A class="" href="http://damieng.com/blog/2008/07/23/linq-to-sql-t4-template-reloaded" mce_href="http://damieng.com/blog/2008/07/23/linq-to-sql-t4-template-reloaded"&gt;templated code generator&lt;/A&gt; sample. One of our regrets from LINQ to SQL V1 days was not providing an easy way to tailor the code-gen. This is one step in that direction.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Another major step would be to preserve "excluded" tables/columns/sprocs/... in dbml. So any change in schema can be handled appropriately as new/deleted database object (a rename could be treated as a removed column and an added column from metadata perspective).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Dinesh&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8842356" width="1" height="1"&gt;</description></item><item><title>Relational-Object-XML-Object with LINQ to SQL &amp; LINQ to XML</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/07/27/relational-object-xml-object-with-linq-to-sql-xml.aspx</link><pubDate>Mon, 28 Jul 2008 08:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8782530</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8782530.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8782530</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8782530</wfw:comment><description>&lt;P&gt;This is old story and I have used parts of it over the last three years to show how LINQ lets you navigate from relational (R)&amp;nbsp;to object (O) or object to XML (X) etc. But for a forthcoming demo, I had to write some quick code today and it looked like it might be worth sharing. So here it is ...&lt;/P&gt;
&lt;P&gt;A little background first: I need to show a 3-tier app where the mid-tier can use a variety of Data Acccess Layers or DALs (not just LINQ to SQL &lt;IMG alt=smile_sad src="http://spaces.live.com/rte/emoticons/smile_sad.gif"&gt; ). A good way to show that is how you can use POCO classes with some extra info. An easy way to populate it is from an XML file. But I would like to continue the demo and show a real DAL talking to a real DB and it would be good to have consistent storyboard and data. So I decided to extract a small subset of AdventureWorks data - Employee-PurchaseOrderHeader-PurchaseOrderDetail into an XML file and then use that file for the first part. So what I have is a nice trip across the three domains: R-&amp;gt; O -&amp;gt; X (file) -&amp;gt; O.&lt;/P&gt;
&lt;P&gt;Here is the R-O-X part. The object model is crafted up in the LINQ to SQL designer with a bunch of unrelated foreign keys (FK) eliminated. I won't repeat it since you can easily create it with drag-drop-member delete gestures in the designer.&lt;/P&gt;
&lt;P&gt;Caution - this is all just a quick and dirty shell to get going. It is not robust with respect to missing files, changed data, test code etc. That is left to you as an exercise &lt;IMG alt=smile_wink src="http://spaces.live.com/rte/emoticons/smile_wink.gif"&gt;&lt;/P&gt;&lt;PRE class=code&gt;AWExtractDataContext db = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;AWExtractDataContext(&lt;SPAN style="COLOR: #a31515"&gt;@"C:\Northwind\AdventureWorks_Data.mdf"&lt;/SPAN&gt;);
db.Log = &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.Out;

&lt;SPAN style="COLOR: green"&gt;// Preselected employees based on browsing of data
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;EmpList = (&lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;db.Employees
              &lt;SPAN style="COLOR: blue"&gt;where &lt;/SPAN&gt;((e.EmployeeID &amp;gt; 240) &amp;amp;&amp;amp; (e.PurchaseOrderHeaders.Any()))
              &lt;SPAN style="COLOR: blue"&gt;select &lt;/SPAN&gt;e).ToList();
&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"\nNumber of employees: {0}\n"&lt;/SPAN&gt;,EmpList.Count);

&lt;SPAN style="COLOR: blue"&gt;foreach &lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;EmpList)
{
    &lt;SPAN style="COLOR: green"&gt;// Select only five POs per employee
    &lt;/SPAN&gt;e.POList = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;PurchaseOrderHeader&amp;gt;(e.PurchaseOrderHeaders.Take(5));
    e.PurchaseOrderHeaders = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;
}

&lt;SPAN style="COLOR: green"&gt;// Write out a single XML hierarchy with some additional denormalized data
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;EmpXML = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XElement(&lt;SPAN style="COLOR: #a31515"&gt;"Employees"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;EmpList
                &lt;SPAN style="COLOR: blue"&gt;select new &lt;/SPAN&gt;XElement(&lt;SPAN style="COLOR: #a31515"&gt;"Employee"&lt;/SPAN&gt;,
                 &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"EmployeeID"&lt;/SPAN&gt;, e.EmployeeID),
                 &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"LoginID"&lt;/SPAN&gt;, e.LoginID),
                 &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"ManagerID"&lt;/SPAN&gt;, e.ManagerID),
                 &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;po &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;e.POList
                 &lt;SPAN style="COLOR: blue"&gt;select new &lt;/SPAN&gt;XElement((&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrder"&lt;/SPAN&gt;),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrderID"&lt;/SPAN&gt;, po.PurchaseOrderID),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"Status"&lt;/SPAN&gt;, po.Status),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"EmployeeID"&lt;/SPAN&gt;, po.EmployeeID),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"OrderDate"&lt;/SPAN&gt;, po.OrderDate),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"ShipDate"&lt;/SPAN&gt;, po.ShipDate),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"SubTotal"&lt;/SPAN&gt;, po.SubTotal),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"TaxAmt"&lt;/SPAN&gt;, po.TaxAmt),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"Freight"&lt;/SPAN&gt;, po.Freight),
                  &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"TotalDue"&lt;/SPAN&gt;, po.TotalDue),
                  &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;det &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;po.PurchaseOrderDetails
                  &lt;SPAN style="COLOR: blue"&gt;select new &lt;/SPAN&gt;XElement((&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrderDetail"&lt;/SPAN&gt;),
                   &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrderID"&lt;/SPAN&gt;, po.PurchaseOrderID),
                   &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrderDetailID"&lt;/SPAN&gt;, det.PurchaseOrderDetailID),
                   &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"ProductID"&lt;/SPAN&gt;, det.ProductID),
                   &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"ProductName"&lt;/SPAN&gt;, det.ProductName),
                   &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"OrderQty"&lt;/SPAN&gt;, det.OrderQty),
                   &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"UnitPrice"&lt;/SPAN&gt;, det.UnitPrice),
                   &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;XAttribute(&lt;SPAN style="COLOR: #a31515"&gt;"LineTotal"&lt;/SPAN&gt;, det.LineTotal)
                   )
                  )
                )
               );

EmpXML.Save(&lt;SPAN style="COLOR: #a31515"&gt;@"C:\temp\AWEmpPOs.xml"&lt;/SPAN&gt;);
&lt;/PRE&gt;
&lt;P&gt;Here is a small portion of the XML from the file.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Employees&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Employee &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;EmployeeID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;241&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;LoginID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;adventure-works\eric2&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;ManagerID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;274&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;PurchaseOrder &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;PurchaseOrderID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;3&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;Status&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;4&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;EmployeeID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;0&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;OrderDate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;2001-05-17T00:00:00&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;ShipDate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;2001-05-26T00:00:00&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;SubTotal&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;8847.3000&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;TaxAmt&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;707.7840&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;Freight&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;221.1825&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;TotalDue&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;9776.2665&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;PurchaseOrderDetail &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;PurchaseOrderID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;3&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;PurchaseOrderDetailID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;4&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;ProductID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;530&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;ProductName&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Seat Post&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;OrderQty&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;550&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;UnitPrice&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;16.0860&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;LineTotal&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;8847.3000&lt;/SPAN&gt;" &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;PurchaseOrder&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;BR&gt;...&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Now in another project, I just took the XML file and created the object hierarchy. This time, I did NOT use any LINQ to SQL or any other DAL-generated classes. I won't bother showing all the POCO classes since the initializer shows you the members and types anyway. But the classes are hand-coded with the auto-implemented properties feature as follows:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Employee
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;public int &lt;/SPAN&gt;EmployeeID { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
    &lt;SPAN style="COLOR: blue"&gt;public string &lt;/SPAN&gt;LoginID { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
    &lt;SPAN style="COLOR: blue"&gt;public int&lt;/SPAN&gt;? ManagerID { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;PurchaseOrder&lt;/SPAN&gt;&amp;gt; POs { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }        
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P mce_keep="true"&gt;The code to populate the object graph is as follows (hierarchy first and backpatching later)&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #2b91af"&gt;XElement &lt;/SPAN&gt;Emps = &lt;SPAN style="COLOR: #2b91af"&gt;XElement&lt;/SPAN&gt;.Load(&lt;SPAN style="COLOR: #a31515"&gt;@"C:\temp\AWEmpPOs.xml"&lt;/SPAN&gt;);

&lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;EmpFromXML =   
        &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;Emps.Elements()
        &lt;SPAN style="COLOR: blue"&gt;select new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Employee
        &lt;/SPAN&gt;{
            EmployeeID = (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;) e.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"EmployeeID"&lt;/SPAN&gt;),
            LoginID = (&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;) e.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"LoginID"&lt;/SPAN&gt;),
            ManagerID = (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;) e.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"ManagerID"&lt;/SPAN&gt;),
            POs = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;PurchaseOrder&lt;/SPAN&gt;&amp;gt;(
                &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;po &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;e.Elements()
                &lt;SPAN style="COLOR: blue"&gt;select new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;PurchaseOrder &lt;/SPAN&gt;{                                
                    PurchaseOrderID = (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;) po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrderID"&lt;/SPAN&gt;),
                    Status = (&lt;SPAN style="COLOR: blue"&gt;byte&lt;/SPAN&gt;) (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;) po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"Status"&lt;/SPAN&gt;),
                    EmployeeID = (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;) po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"EmployeeID"&lt;/SPAN&gt;),
                    OrderDate = (&lt;SPAN style="COLOR: #2b91af"&gt;DateTime&lt;/SPAN&gt;) po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"OrderDate"&lt;/SPAN&gt;), 
                    ShipDate = (&lt;SPAN style="COLOR: #2b91af"&gt;DateTime&lt;/SPAN&gt;?) po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"ShipDate"&lt;/SPAN&gt;),
                    SubTotal = (&lt;SPAN style="COLOR: blue"&gt;decimal&lt;/SPAN&gt;) po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"SubTotal"&lt;/SPAN&gt;),
                    TaxAmt = (&lt;SPAN style="COLOR: blue"&gt;decimal&lt;/SPAN&gt;)po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"TaxAmt"&lt;/SPAN&gt;),
                    Freight = (&lt;SPAN style="COLOR: blue"&gt;decimal&lt;/SPAN&gt;)po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"Freight"&lt;/SPAN&gt;),
                    TotalDue = (&lt;SPAN style="COLOR: blue"&gt;decimal&lt;/SPAN&gt;)po.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"TotalDue"&lt;/SPAN&gt;),
                    Details = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;PurchaseOrderDetail&lt;/SPAN&gt;&amp;gt; (
                        &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;det &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;po.Elements()
                        &lt;SPAN style="COLOR: blue"&gt;select new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;PurchaseOrderDetail &lt;/SPAN&gt;{
                            PurchaseOrderID = (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;)det.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrderID"&lt;/SPAN&gt;),
                            PurchaseOrderDetailID = (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;)det.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"PurchaseOrderDetailID"&lt;/SPAN&gt;),
                            ProductID = (&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;)det.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"ProductID"&lt;/SPAN&gt;),
                            ProductName = (&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;)det.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"ProductName"&lt;/SPAN&gt;),
                            OrderQty = (&lt;SPAN style="COLOR: blue"&gt;short&lt;/SPAN&gt;)det.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"OrderQty"&lt;/SPAN&gt;),
                            UnitPrice = (&lt;SPAN style="COLOR: blue"&gt;decimal&lt;/SPAN&gt;)det.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"UnitPrice"&lt;/SPAN&gt;),
                            LineTotal = (&lt;SPAN style="COLOR: blue"&gt;decimal&lt;/SPAN&gt;)det.Attribute(&lt;SPAN style="COLOR: #a31515"&gt;"LineTotal"&lt;/SPAN&gt;)
                        }
                        )
                }
              )
        };

&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Employee&lt;/SPAN&gt;&amp;gt; EmpList = EmpFromXML.ToList();

&lt;SPAN style="COLOR: green"&gt;// Backpatch the references based on collection membership
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;Employee &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;EmpList)
    &lt;SPAN style="COLOR: blue"&gt;foreach &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;PurchaseOrder &lt;/SPAN&gt;po &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;e.POs)
    {
        po.Employee = e;
        &lt;SPAN style="COLOR: blue"&gt;foreach &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;PurchaseOrderDetail &lt;/SPAN&gt;det &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;po.Details)
            det.PurchaseOrder = po;
    }

&lt;SPAN style="COLOR: green"&gt;// Show some of the constructed graph
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ObjectDumper&lt;/SPAN&gt;.Write(EmpList.First(), 1);&lt;/PRE&gt;
&lt;P&gt;I found it quite easy and quick to roll this up. You might find it useful where you need to combine data from the three domains and go back and forth.&lt;/P&gt;
&lt;P&gt;Dinesh&lt;/P&gt;
&lt;P&gt;P.S. &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In case you haven't used it before, ObjectDumper is the new incarnation of Console.WriteLine(). It shipped as a sample with Visual Studio 2008 in source form so you will need to build it into a DLL and add a reference to your project. It is well worth it. 
&lt;LI&gt;Before you say it ... When you have a hammer, everything looks like a nail. But LINQ is an awesome hammer - it often works better than screwdrivers and spanners &lt;IMG alt=smile_regular src="http://spaces.live.com/rte/emoticons/smile_regular.gif"&gt; 
&lt;LI&gt;I could have used a smart collection to backpatch the reference to the parent object but I just got lazy and wrote some imperative code that traverses the hierarchy again.&lt;/LI&gt;&lt;/OL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8782530" width="1" height="1"&gt;</description></item><item><title>LINQ to SQL Tips 9: Understanding DataContext's internal caching </title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/07/01/linq-to-sql-tips-9-understanding-datacontext-s-internal-caching.aspx</link><pubDate>Wed, 02 Jul 2008 07:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8680059</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8680059.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8680059</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8680059</wfw:comment><description>&lt;P&gt;Back to the "tips" series after a little break ...&lt;/P&gt;
&lt;P&gt;One common question I get is about caching of data in LINQ to SQL. It means a lot of different things so let's start with the following baseline: LINQ to SQL was designed to get you objects from the database and to submit the changes back to the database. It is not intended to be a mid-tier caching component. It is not a cache and it does not pretend to be one. However, it does have certain behaviors that are interesting in this regard:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Object identity&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you want to be able to update the objects you retrieve from the database, it helps to avoid multiple copies of the objects. LINQ to SQL maintains an internal "identity cache" to ensure that within the scope of a DataContext, there will be at most one instance of a given type for a given key value. Think of it like a dictionary indexed by the key value (whether single column or composite key) that stores entities. When you enumerate the results of a query, DataContext looks at each row returned by the underlying DataReader, checks if an instance with the same key value already exists in the dictionary. If an entity is found, it throws away the row and just returns you the existing object from the identity cache. (For those who are more curious, you can look at DataContext.cs, IdentityManager.cs in the sources). As described in another post, we don't stomp on your copy while materializing objects (unless you ask for that using Refresh())&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Change tracking&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;After query execution, you are out of the relational world and into the brave world of objects. There the currency for identity is an object reference rather than a key value since APIs take in objects and not rows or key values. So we also maintain a dictionary that can be looked up by the object. Among many other things, it helps us Attach() a new object by starting to track it. &lt;/P&gt;
&lt;P&gt;Enough of the internal view. What does it mean for you?&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;LINQ to SQL is designed for retrieving and saving objects. Any caching it does is to that end and not for general purpose use you may have. There are other cache components you can look at.&lt;/LI&gt;
&lt;LI&gt;By and large, DataContext holds a reference to an&amp;nbsp;entity that it materializes for the life of the DataContext and keeps it as is unless you explicitly modify it or &lt;A class="" href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/23/linq-to-sql-tips-6-how-to-refresh-given-datacontext-won-t-stomp-on-your-objects.aspx" mce_href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/23/linq-to-sql-tips-6-how-to-refresh-given-datacontext-won-t-stomp-on-your-objects.aspx"&gt;Refresh()&lt;/A&gt; it.&lt;/LI&gt;
&lt;OL&gt;
&lt;LI&gt;You can ask for it by the key value and retrieve it without remote query (this bug is getting fixed in SP1)&lt;/LI&gt;
&lt;LI&gt;DataContext feels like&amp;nbsp;it has an&amp;nbsp;obsessive possessive disorder. You can't really take away an object from it. It would rather be disposed than give up the precious entities it holds on to. If you don't like the fact that a reference is maitained (i.e. you want to have entities garbage collected), then use the disposable pattern. See &lt;A class="" href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx" mce_href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx"&gt;this post&lt;/A&gt; for more information.&lt;/LI&gt;&lt;/OL&gt;
&lt;LI&gt;Over time, the entities in the id cache&amp;nbsp;get more and more stale. Fine for reference data; not OK for data that changes in the database more often.&lt;/LI&gt;
&lt;LI&gt;The internal caches make DataContext a write-back cache rather than a write-through cache. We write back on SubmitChanges().&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Attach() might look like an Add() on the cache (and it does behave like it in some ways), but it is &lt;A class="" href="http://blogs.msdn.com/dinesh.kulkarni/archive/2007/10/08/attach-if-you-have-something-detached.aspx" mce_href="http://blogs.msdn.com/dinesh.kulkarni/archive/2007/10/08/attach-if-you-have-something-detached.aspx"&gt;designed for tracking the object&lt;/A&gt; for further changes. &lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Non-entities don't show up in the internal cache - there is no key for lookup. Most common case of non-entity is a result from a sproc that does not match the shape of an entity. &lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Turning ObjectTrackingEnabled off can give you a small perf boost - may be useful in a read-only app (only).&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P mce_keep="true"&gt;Dinesh&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8680059" width="1" height="1"&gt;</description></item><item><title>An account of Bill Gates' farewell</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/06/28/an-account-of-billg-farewell.aspx</link><pubDate>Sun, 29 Jun 2008 00:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8664910</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8664910.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8664910</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8664910</wfw:comment><description>&lt;P&gt;An unusual subject for this blog that has been mostly about components I have worked on. But the event yesterday was memorable and worth sharing. The &lt;A class="" href="http://www.microsoft.com/presspass/presskits/leadership/video.mspx" mce_href="http://www.microsoft.com/presspass/presskits/leadership/video.mspx"&gt;event&lt;/A&gt; has been covered widely so I won't even try to broadly summarize. Insted I will list what I found interesting. I was lucky enough (one of 2k lottery winners out of maybe 20+k who were interested) to get a seat for in-person viewing.&lt;/P&gt;
&lt;P&gt;There is no substitute to hearing from the man himself and his business partner of 28 years (and a friend/associate of 35 years or so) Steve Ballmer. The range of topics chosen was very enlightening - from "How did your parents react to you dropping out" to "What was the biggest screw up and what did you learn from it". Here are three things I took away from it:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Trust and personal networks matter the most&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no substitute for personal networks and personal trust and gut instinct. For all the talk of globalization, outcome/evidence-based hiring and rewards, creative processes like forming businesses are deeply personal rather than global; intuitive rather than analytical and grounded in optimism/aspirations rather than backward looking statistics. Maybe the takeaway suits my personality profile but I am always uneasy about decision making processes that try to reduce human judgement to an automaton. SteveB was a known quantity, his passion and intelligence was vetted long before there was any Microsoft, let alone a job opening.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;How others see you differs from your self-model&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Peronal motivations and self-image can be very far apart from the motivations attributed by others to you and their image of you. This gap is very important to understand. I was not an MS employee during the major anti-trust proceedings. But after hearing from BillG and SteveB about their mindset and approach and after hearing quixotic evil intentions attribute to my team and I during the last few years, I think the aforementioned gap explains a lot.I won't even bother talking about our good intentions. That is too touchy feely. But from what I have seen, my colleagues in various teams and I are so preoccupied with building what we are building and getting it out the door (before it gets killed for some bizarre internal reasons :-) ) that we have no time or smarts left to even think about doing any sinister things. Let alone plan for it years in advance and execute on it to perfection. Heck, like software engineers everywhere, we have a tough time estimating and meeting the estimates for the most basic product/component we would like to ship.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Decisions are based on aspiration and hope rather than just analytics&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There is no shortage of blog posts or news items calling for radical strategy/personnel/... change. Most wonder why those in the position of power cannot see what the numbers and facts show. A lot is based on intuition about strategy/leadership/vision that can be counter to facts on the ground at a particular point in time. That doesn't validate the intuition or negate the facts. It simply means that it is futile to look for the fact-based-decision making automaton. Hear the vision, strategy and then lead. follow or get out based on your personal judgement.&lt;/P&gt;
&lt;P&gt;Like the takeaways, my process of arriving at them was deeply personal. Take it (or not) FWIW.&lt;/P&gt;
&lt;P&gt;Dinesh&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8664910" width="1" height="1"&gt;</description></item><item><title>Design of LINQ to SQL - What was I thinking or was I?</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/06/24/design-of-linq-to-sql-and-core-linq-what-were-we-thinking.aspx</link><pubDate>Wed, 25 Jun 2008 08:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8651029</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8651029.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8651029</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8651029</wfw:comment><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;A little break from my "LINQ to SQL tips" series of posts. A recent &lt;A class="" href="http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/" mce_href="http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/"&gt;vote of no confidence&lt;/A&gt; on a related component orchestrated by community activists reminded me of many questions I have fielded and how the design team approached the design of LINQ to SQL (and also core LINQ APIs and C# language changes for LINQ). Nah, that’s for another day when it is cloudy and raining.&amp;nbsp;Instead, let’s talk about my recent dream. Or rather, a&amp;nbsp;nightmare!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;But first turn off your flame throwers, grab a cup of coffee and don't take this too seriously ...&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&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;I had this Q&amp;amp;A&amp;nbsp;nightmare about the component I worked on - LINQ to SQL. I am the "expert" providing the non-answers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Q: How do I&amp;nbsp;use blah pattern with LINQ to SQL (e.g. blah = ActiveRecord if&amp;nbsp;you don't like&amp;nbsp;abstract concepts)&lt;BR&gt;A: You don't!&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Q: I think I wasn't sufficiently clear. I stood on one leg and when the phase of the moon was 64% of full, it worked but now that the moon is waxing further, your foo method throws bar exception when I do baz. How do I just get that bit working with LINQ to SQL. &lt;BR&gt;A: You don't&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Q: (By now quite upset) Do you even understand blah?&lt;BR&gt;A: (Forced to be less terse) Yes. We considered blah and decided against it for a set of reasons listed below. That pattern is not consistent with the core design assumptions and recommended usage patterns with LINQ to SQL.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Q: (Now a full-force verdict) I hearby find you guilty of violating the implicit agreement to solve the world hunger problem using blah methodology.&amp;nbsp;Hence, what you produced is useless, evil and must be stopped at once. Any software built using your component will accelerate global warming and cause all glaciers to melt at once. And of course, it will irreparably damage the young and impressionable minds of generations of developers leaving them utterly useless for anything except writing some old fashioned code.&lt;BR&gt;A: Thank you for your interest in LINQ to SQL err blah.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Nightmare aside,&amp;nbsp;(what) were we thinking? Stay tuned for&amp;nbsp;that ...&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;P.S.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #c0504d; mso-themecolor: accent2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;1. This release includes backward-looking statements intended to qualify for the safe harbor from liability established by the Public Flagellation by Community&amp;nbsp;Act of 2008. These backward-looking statements generally can be identified by phrases such as "did", "was", "thought" ... and by the absence of "will" "fix" "in future release".&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="COLOR: #c0504d; mso-themecolor: accent2"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;2.&amp;nbsp;I just wanted to get you objects from the table. I swear. Nothing more than that!&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;SPAN style="COLOR: #c0504d; mso-themecolor: accent2"&gt;&lt;FONT face=Calibri&gt;3. Scott B., if you are reading this, peace! I won't let you drag me on to the stage at another PDC BoF and I won't fix anything either. I can't. I don't drive LINQ to SQL anymore. I just drive righteous developers crazy &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #c0504d; FONT-FAMILY: Wingdings; mso-themecolor: accent2; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;&lt;SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;J&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN style="COLOR: #c0504d; mso-themecolor: accent2"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8651029" width="1" height="1"&gt;</description></item><item><title>LINQ to SQL Tips 8: How to (and why) create a partial class in the designer to augment generated code</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/06/06/linq-to-sql-tips-8-how-to-and-why-create-a-partial-class-in-the-designer-to-augment-generated-code.aspx</link><pubDate>Sat, 07 Jun 2008 03:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8579309</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8579309.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8579309</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8579309</wfw:comment><description>&lt;P&gt;The code generated for LINQ to SQL is a set of partial classes - one for your DataContext and one per entity mapped to a table or a view. That means you have the opportunity to augment the generated code with additional code in your partial class. I often get questions that have a simple answer in the following list. The code you write could be for:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Adding unmapped fields or properties to an entity class&amp;nbsp;(e.g. computed property - amount for an Order class based on price, quantity, freight, taxes etc.)&lt;/LI&gt;
&lt;LI&gt;Providing an implementation of a validation method defined as a partial method (e.g. for a mapper property called "Name", OnNameChanging(), OnNameChanged()&amp;nbsp;or for an entity&amp;nbsp;OnValidate() etc)&lt;/LI&gt;
&lt;LI&gt;Providing an implementation of CUD&amp;nbsp;override methods supported by the DataContext (e.g.&amp;nbsp;InsertOrder, UpdateOrder, DeleteOrder). You may choose to call a method wrapping a CUD sproc in the method body and/or do more customization.&lt;/LI&gt;
&lt;LI&gt;Providing an implementation&amp;nbsp;of relationship load override method (e.g. LoadOrders(Customer cust), LoadCustomer(Order ord) etc.). Again, you may choose to call a method wrapping a query sproc in the method body and/or do more customization.&lt;/LI&gt;
&lt;LI&gt;Add a method to call a sproc returning multiple results (see &lt;A class="" href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/16/linq-to-sql-tips-7.aspx" mce_href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/16/linq-to-sql-tips-7.aspx"&gt;this&lt;/A&gt; previous post for more details)&lt;/LI&gt;
&lt;LI&gt;Adding utility methods to entity classes or your DataContext class &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;That sounds like a good bunch of reasons. But I often get a followup question - is there an easy way to do this&amp;nbsp;in the designer? Of course, you can add a new class to a project anytime but a somewhat stylized way is to right click on the design surface and click "View code" (don't ask me why that name was chosen for creating a new partial class). If I do that for Northwind.dbml (file opened in the designer), I get a Northwind.cs at a peer to Northwind.designer.cs. &lt;/P&gt;
&lt;P&gt;The file already contains a little class wrapper. It is not a big deal to add that by hand using code snippets but it is another little bit we could do for you (and did in this case).&lt;/P&gt;
&lt;P&gt;Dinesh&lt;/P&gt;
&lt;P mce_keep="true"&gt;June 16 addendum: Steve has rightly pointed out that the behavior is different in website projects. My colleague Young Joo&amp;nbsp;- PM for the designer explained the rational as follows "&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-language: HI; mso-fareast-font-family: PMingLiU; mso-bidi-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-ansi-language: EN-US; mso-fareast-language: ZH-TW"&gt;We disabled View Code in website project since it actually has a different meaning than other project types.&amp;nbsp; The View Code option from Dataset Designer within Windows Application project, for instance, creates the partial class file.&amp;nbsp; However, it opens .XSD file in the editor in website project.&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P mce_keep="true"&gt;So in website project, you will need to resort to the good old way of adding a class through the solution explorer. Thanks Steve!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8579309" width="1" height="1"&gt;</description></item><item><title>LINQ to SQL Tips 7: Minimal update when you don't want optimistic concurrency check</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/06/01/linq-to-sql-tips-7-minimal-update-when-you-don-t-want-optimistic-concurrency-check.aspx</link><pubDate>Mon, 02 Jun 2008 09:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8568808</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8568808.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8568808</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8568808</wfw:comment><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;The common guidance for updates is to keep the original values in view state so that you can recreate the object in its original state, Attach() it and then set the values that the user has modified. This works well for the most part. But at times, a user is allowed to to set only certain values (e.g. Product.UnitsInStock) and is allowed to set them without fear of concurrent change (i.e. optimistic concurrency conflict).&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;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;There are two parts to the generated SQL update command:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;SET clause: This is always minimal; i.e. only the changed columns are included by comparing original and current versions of the object. Hence, all properties don’t have to be set &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;WHERE clause: By default, L2S (designer or SqlMetal) assume that all columns participate in opt concurrency and generates a full WHERE clause. What you seem to want in the example below is turning off (or limiting) optimistic concurrency. That option is available but tedious in the designer. For each class member, UpdateCheck can be set to “Never” in the property grid. This is not possible through SqlMetal (unless there is a column of timestamp type in which case, that is the only column used in opt concurrency check)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;The code below _&lt;I&gt;simulates&lt;/I&gt;_ what you would do with just a few (or one) values available in post-back. Please see &lt;A href="http://blogs.msdn.com/dinesh.kulkarni/archive/2007/10/08/attach-if-you-have-something-detached.aspx" mce_href="http://blogs.msdn.com/dinesh.kulkarni/archive/2007/10/08/attach-if-you-have-something-detached.aspx"&gt;this post&lt;/A&gt; before using Attach() in a simple 2-tier app. Here, I manually set UpdateCheck to Never for all Product class members one by one in the designer. As a result, the update for UnitsInStock succeeded even though I don’t have the original values.&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;/FONT&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;NorthwindDataContext&lt;/SPAN&gt; db = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;NorthwindDataContext&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;@"C:\Northwind\Northwnd.mdf"&lt;/SPAN&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.Log = &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.Out;&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // simulate minimal product information available by creating a new one&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Product&lt;/SPAN&gt; prod = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Product&lt;/SPAN&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// ID is essential and cannot be skipped&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prod.ProductID = 8;&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.Products.Attach(prod);&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// Change just one property&lt;/SPAN&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prod.UnitsInStock = 11;&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: 'Lucida Console'"&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="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.SubmitChanges();&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: 'Lucida Console'"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&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;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-language: HI; mso-fareast-font-family: 'Times New Roman'"&gt;Of course, you must think through very carefully if you want optimistic concurrency check or not. It depends on the semantics of your application.&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: 'Arial','sans-serif'; mso-bidi-language: HI; mso-fareast-font-family: 'Times New Roman'"&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="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-bidi-language: HI; mso-fareast-font-family: 'Times New Roman'"&gt;As an aside, if the designer only provided a single class level property to turn off UpdateCheck for all members, the above solution would be much more palatable. Right now it is a bit tedious when you use the designer.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8568808" width="1" height="1"&gt;</description></item><item><title>LINQ to SQL Tips 6: How to refresh given DataContext won't stomp on your objects </title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/23/linq-to-sql-tips-6-how-to-refresh-given-datacontext-won-t-stomp-on-your-objects.aspx</link><pubDate>Sat, 24 May 2008 03:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8543152</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8543152.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8543152</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8543152</wfw:comment><description>&lt;P&gt;The DataContext is a rather careful beast. Once an object is retrieved, the DataContext will not stomp on it if a query returns the same object again. This is intentional. Imagine the chaos if you modified some of the retrieved objects or even read the values and made some decision based on that and then the results of a subsequent query just stomped all over that object with newly changed values from the database.&lt;/P&gt;
&lt;P&gt;But that does create a separate problem: if you want to get the new values from the database and want your object overwritten, simply querying will not do. DataContext will faithfully execute the queries and bring back the rows with new data for old objects but the rows will be effectively discarded if an object with the same id exists in the cache.&lt;/P&gt;
&lt;P&gt;The &lt;A class="" href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.refresh.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.refresh.aspx"&gt;Refresh&lt;/A&gt;()&amp;nbsp;method could be used. It is primarily designed for optimistic concurrency conflict resolution and requires you to state what objects you care to refresh. If you are using it, keep in mind that the changes in the database for a given query can be:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Newly inserted objects&lt;/LI&gt;
&lt;LI&gt;Updates of existing objects&lt;/LI&gt;
&lt;LI&gt;Deleted objects that were present in a previous execution of the same query&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Issuing the same query with the same DataContext takes care of the first. Refresh() can handle #2. But #3 requires a little more thought and computation. You could certainly use another DataContext to compare results. But ...&lt;/P&gt;
&lt;P&gt;Why is there always a "but"? It is there because if you find your design getting too complicated, it is time to revisit the problem and question the scenario. Are you really using the &lt;A class="" href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx" mce_href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx"&gt;DataContext lifetime wisely&lt;/A&gt;? Why are you keeping the DataContext instance for so long that you are getting into these issues? Is it time to toss the old DataContext instance and create a new one (e.g. to periodically recycle reference data - maybe once every n hours)? Is it time to use two different instances for reference data vs transactional data?&lt;/P&gt;
&lt;P&gt;I can't answer these questions for your app. But if you think about them, you will likely have a better design. And maybe you won't need a query refresh! In the design of LINQ to SQL, we often pulled back from complex designs when we felt the designs were way off the main road wandering in the woods. More about that design philosophy followed in the C# design meeting some other day. Meanwhile, hope you find some of the questioning refreshing :-)&lt;/P&gt;
&lt;P&gt;Dinesh&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8543152" width="1" height="1"&gt;</description></item><item><title>LINQ to SQL Tips 5: Using stored procs that return multiple results</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/16/linq-to-sql-tips-7.aspx</link><pubDate>Sat, 17 May 2008 04:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8516201</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8516201.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8516201</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8516201</wfw:comment><description>&lt;P&gt;Often I get the following questions about stored procs in LINQ to SQL:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I have sproc that returns multiple results. How can I use it in LINQ to SQL?&lt;/LI&gt;
&lt;LI&gt;Can I use a sproc that returns results of different shapes; e.g. Customers and Orders?&lt;/LI&gt;
&lt;LI&gt;I drag-dropped a sproc returning multiple results on the designer surface. But I don't get a method returning multiple results. What is missing?&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Here is the overall answer.&lt;/P&gt;
&lt;P&gt;Yes, you can use sprocs returning multiple results of different shapes. Here is an example:&lt;/P&gt;
&lt;P&gt;This should be added to your partial class that is derived from DataContext:&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&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;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Function(Name=&lt;SPAN style="COLOR: maroon"&gt;"dbo.MultipleResultTypesSequentially"&lt;/SPAN&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ResultType(&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(Product))]&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ResultType(&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(Customer))]&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; IMultipleResults MultipleResultTypesSequentially()&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IExecuteResult result = &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ExecuteMethodCall(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;, ((&lt;SPAN style="COLOR: teal"&gt;MethodInfo&lt;/SPAN&gt;)(&lt;SPAN style="COLOR: teal"&gt;MethodInfo&lt;/SPAN&gt;.GetCurrentMethod())));&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; ((IMultipleResults)(result.ReturnValue));&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: 'Lucida Console'"&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: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&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: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&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="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;In consuming code, here is how it can be used&lt;/FONT&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: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using(IMultipleResults sprocResults = db.MultipleResultTypesSequentially()) {&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;Product&amp;gt; prods = sprocResults.GetResult&amp;lt;Product&amp;gt;().ToList();&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;Customer&amp;gt; custs = sprocResults.GetResult&amp;lt;Customer&amp;gt;().ToList();&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; …&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: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;And no, the designer does not support this feature. So you have to add the method in your partial class. SqlMetal does however extract the sproc. The reason for that is an implementation detail: the two use the same code generator but different database schema extractors.&lt;/P&gt;
&lt;P&gt;Anyway, with or without SqlMetal, you can use the feature as described above.&lt;/P&gt;
&lt;P&gt;Dinesh&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8516201" width="1" height="1"&gt;</description></item><item><title>LINQ to SQL Tips 4: Use DeleteOnNull if you want to delete object with null FK </title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/11/linq-to-sql-tips-4-use-deleteonnull-if-you-want-to-delete-object-with-null-fk.aspx</link><pubDate>Sun, 11 May 2008 21:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8488127</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8488127.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8488127</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8488127</wfw:comment><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;I often get a question along the following lines:&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&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;If I remove one of the OderDetails from Order.OrderDetails collection, I see that the reference OrderDetail.Order is set to null but this just orphans the OrderDetail; it is not deleted. How can I change that?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Here is how:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;This is not exposed in the designer so you will need to change the generated code (ouch!). In the Association attribute, set the DeleteOnNull property to true as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Once this is set, either of the following operations &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;&lt;v:shapetype id=_x0000_t202 path="m,l,21600r21600,l21600,xe" coordsize="21600,21600" o:spt="202"&gt;&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;&lt;v:path gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;&lt;/v:shapetype&gt;&lt;v:shape id=_x0000_s1027 style="WIDTH: 471.1pt; HEIGHT: 27.5pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line; mso-width-relative: margin; mso-height-relative: margin" type="#_x0000_t202" fillcolor="#eeece1"&gt;&lt;v:textbox style="mso-next-textbox: #_x0000_s1027"&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=0 width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" style="BORDER-LEFT-COLOR: #f0f0f0; BORDER-BOTTOM-COLOR: #f0f0f0; BORDER-TOP-COLOR: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #f0f0f0"&gt;
&lt;DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes; mso-bidi-font-family: Mangal; mso-bidi-language: HI"&gt;ord.Order_Details.Remove(od); &lt;SPAN style="COLOR: green"&gt;// ord is Order; od is OrderDetail&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes; mso-bidi-font-family: Mangal; mso-bidi-language: HI"&gt;od.Order = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 10.0pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/v:textbox&gt;&lt;?xml:namespace prefix = w ns = "urn:schemas-microsoft-com:office:word" /&gt;&lt;w:wrap type="none"&gt;&lt;/w:wrap&gt;&lt;w:anchorlock&gt;&lt;/w:anchorlock&gt;&lt;/v:shape&gt;&lt;v:shapetype id=_x0000_t75 path="m@4@5l@4@11@9@11@9@5xe" coordsize="21600,21600" o:spt="75" o:preferrelative="t" filled="f" stroked="f"&gt;&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;&lt;v:formulas&gt;&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;&lt;/v:formulas&gt;&lt;v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f"&gt;&lt;/v:path&gt;&lt;o:lock v:ext="edit" aspectratio="t"&gt;&lt;/o:lock&gt;&lt;/v:shapetype&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;will result in the following being inferred:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;v:shape id=_x0000_s1026 style="WIDTH: 471.1pt; HEIGHT: 28.7pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line; mso-width-relative: margin; mso-height-relative: margin" type="#_x0000_t202" fillcolor="#eeece1"&gt;&lt;v:textbox style="mso-next-textbox: #_x0000_s1026"&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=0 width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" style="BORDER-LEFT-COLOR: #f0f0f0; BORDER-BOTTOM-COLOR: #f0f0f0; BORDER-TOP-COLOR: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #f0f0f0"&gt;
&lt;DIV&gt;
&lt;P style="MARGIN-LEFT: 0.5in"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes; mso-bidi-font-family: Mangal"&gt;// db is an instance of the strongly typed DataContext&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes; mso-bidi-font-family: Mangal"&gt;db.Order_Details.DeleteOnSubmit(od); &lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-size: 10.0pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/v:textbox&gt;&lt;w:wrap type="none"&gt;&lt;/w:wrap&gt;&lt;w:anchorlock&gt;&lt;/w:anchorlock&gt;&lt;/v:shape&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;Please note that this is not the same as cascade delete. Cascade delete is what you specify on your foreign key in the database - for all apps. LINQ to SQL deliberately does not take over this database role. What it does is provide a shorthand notation to say that a particular type is the &lt;EM&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'"&gt;target&lt;/SPAN&gt;&lt;/EM&gt; of cascade delete constraint in the database (&lt;EM&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'"&gt;not the source&lt;/SPAN&gt;&lt;/EM&gt;) and hence can be cleaned up when the nullable foreign key is set to null. LINQ to SQL does not by itself provide cascade delete behavior.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8488127" width="1" height="1"&gt;</description></item><item><title>LINQ to SQL Tips 3: Deferred (lazy) or eager loading of related objects with stored procs</title><link>http://blogs.msdn.com/dinesh.kulkarni/archive/2008/05/05/linq-to-sql-tips-3-deferred-lazy-loading-of-related-objects-with-stored-procs.aspx</link><pubDate>Tue, 06 May 2008 08:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8462291</guid><dc:creator>Dinesh.Kulkarni</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/dinesh.kulkarni/comments/8462291.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dinesh.kulkarni/commentrss.aspx?PostID=8462291</wfw:commentRss><wfw:comment>http://blogs.msdn.com/dinesh.kulkarni/rsscomments.aspx?PostID=8462291</wfw:comment><description>&lt;P&gt;This post is a confluence of two distinct sets of comments I got:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The above-mentioned feature is a well-hidden secret; and&lt;/LI&gt;
&lt;LI&gt;I post code only in C# while there is a big community of VB users who like LINQ to SQL&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;So here we go ...&lt;/P&gt;
&lt;P&gt;First, the &lt;A class="" href="http://msdn.microsoft.com/en-us/library/bb546186.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb546186.aspx"&gt;MSDN docs on this topic&lt;/A&gt; are a bit too terse and don't describe the purpose of LoadXyz as well as they could. That is perhaps the result of clubbing too many features in one small topic.&lt;/P&gt;
&lt;P&gt;Stored procedures can be used for any of the following purposes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Queries for objects&lt;/LI&gt;
&lt;LI&gt;Insert, Update, Delete operations&lt;/LI&gt;
&lt;LI&gt;Deferred or eager loading of related objects (i.e. indirectly queried objects based on navigation)&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The support for the first is quite well known as the designer exposes that feature quite well. Drag and drop a sproc on the right hand pane and you get a method wrapping the sproc. That works for single or multiple results returned.&lt;/P&gt;
&lt;P&gt;The support for the second group takes a little more work in the designer as you have to configure the behavior and associate parameters. This is also covered in the documentation&amp;nbsp;topic mentioned above.&lt;/P&gt;
&lt;P&gt;That leaves the most interesting feature. Many ORMs support the first two categories above but when it comes to loading of related objects (e.g. Products for a given category object), you often need dynamic SQL. But you don't want to lose the power of the dot just because your DBA does not allow dynamic SQL! You still want to go from a category to its products collection and be able to see the products loaded. Plus ideally this should work for both eager and deferred (or lazy) loading. That is the purpose of the LoadXyz methods. Here is a VB sample that shows how to use them:&lt;/P&gt;
&lt;P&gt;In your NorthwindDataContext partial class, just add the following (see comments for assumed sprocs)&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Override loading of Category.Products by using method wrapper. Assume method named CategoryProducts that wraps a sproc &lt;/SPAN&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="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; LoadProducts(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; category &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Category) &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt;&amp;nbsp; _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IEnumerable(&lt;SPAN style="COLOR: blue"&gt;Of&lt;/SPAN&gt; Product)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.CategoryProducts(category.CategoryID)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;' Override loading of Product.Category by using method wrapper. Assume method named CategoryById that wraps a sproc&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt; LoadCategory(&lt;SPAN style="COLOR: blue"&gt;ByVal&lt;/SPAN&gt; product &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Product) &lt;SPAN style="COLOR: blue"&gt;As&lt;/SPAN&gt; Category&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;Return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.CategoryById(product.CategoryID).Single()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt 30.75pt; VERTICAL-ALIGN: top; LINE-HEIGHT: 140%"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 140%; FONT-FAMILY: 'Lucida Console'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;Function&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Now, somecategory.Products and someProduct.Category will work without the need for dynamic SQL and with eager and lazy loading. (BTW, these LoadXyz methods are not intended for top level query - for that all you need to do is call a method wrapping a sproc or write a query that goes against the relevant TVF instead of the table).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I really like this feature, do you?&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Update 1 (5/5/08): If you like tricks, not just tips and if you are not faint of the heart, then you&amp;nbsp;must check Matt's latest posting about &lt;/EM&gt;&lt;A class="" href="http://blogs.msdn.com/mattwar/archive/2008/05/04/mocks-nix-an-extensible-linq-to-sql-datacontext.aspx" mce_href="http://blogs.msdn.com/mattwar/archive/2008/05/04/mocks-nix-an-extensible-linq-to-sql-datacontext.aspx"&gt;&lt;EM&gt;mockable DataContext&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;. Even if you don't care about TDD, mocking etc., it is a good reminder of how certain mechanisms can be repurposed for new and bizarre (in a good way) goals.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8462291" width="1" height="1"&gt;</description></item></channel></rss>