<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://mtaulty.com/CommunityServer/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>Mike Taulty's Blog : SQLServer</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx</link><description>Tags: SQLServer</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Debug Build: 40407.4157)</generator><item><title>13th May – Session at the SQL Servers User’s Group at Microsoft, Reading</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/05/12/13th-may-session-at-the-sql-servers-user-s-group-at-microsoft-reading.aspx</link><pubDate>Tue, 12 May 2009 09:08:56 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:11336</guid><dc:creator>mtaulty</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=11336</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=11336</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/05/12/13th-may-session-at-the-sql-servers-user-s-group-at-microsoft-reading.aspx#comments</comments><description>&lt;p&gt;Just a quick plug – tomorrow evening I’m doing a session on ADO.NET Data Services (“Astoria”) at the SQL Server User’s Group at Microsoft, Reading.&lt;/p&gt;  &lt;p&gt;See here for details;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a title="http://sqlserverfaq.com/events/167/Sessions-on-Understanding-ADONET-Data-Services-Windows-7-features-indepth-and-the-usual-SQL-Nuggets-and-Networking.aspx" href="http://sqlserverfaq.com/events/167/Sessions-on-Understanding-ADONET-Data-Services-Windows-7-features-indepth-and-the-usual-SQL-Nuggets-and-Networking.aspx"&gt;http://sqlserverfaq.com/events/167/Sessions-on-Understanding-ADONET-Data-Services-Windows-7-features-indepth-and-the-usual-SQL-Nuggets-and-Networking.aspx&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;it’d be great to see you there.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=11336" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/XML/default.aspx">XML</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/WebServices/default.aspx">WebServices</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/VisualStudio/default.aspx">VisualStudio</category></item><item><title>Virtual Earth &amp; SQL Server Event – London, April 16th</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/04/01/virtual-earth-sql-server-event-london-april-16th.aspx</link><pubDate>Wed, 01 Apr 2009 10:55:18 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:11237</guid><dc:creator>mtaulty</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=11237</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=11237</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/04/01/virtual-earth-sql-server-event-london-april-16th.aspx#comments</comments><description>&lt;p&gt;Johannes Kerbeck and Simon Sabin are running an event around Virtual Earth in the Microsoft offices in London on April 16th.&lt;/p&gt;  &lt;p&gt;Sounds like an interesting take on things to me is that it seems to be angled more around taking spatial data and applying it in both places.&lt;/p&gt;  &lt;p&gt;More details from &lt;a href="http://www.viawindowslive.com/VirtualEarthEvent.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You won’t see me there though. I’ll be &lt;a href="http://www.nxtgenug.net/ViewEvent.aspx?EventID=199"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=11237" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/WindowsLive/default.aspx">WindowsLive</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/UKCommunities/default.aspx">UKCommunities</category></item><item><title>ADO.NET Data Services Session at SQL Bits Manchester</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/03/28/ado-net-data-services-session-at-sql-bits-manchester.aspx</link><pubDate>Sat, 28 Mar 2009 13:05:39 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:11227</guid><dc:creator>mtaulty</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=11227</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=11227</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/03/28/ado-net-data-services-session-at-sql-bits-manchester.aspx#comments</comments><description>&lt;p&gt;A big thanks to all the people who came along to my session at &lt;a href="http://sqlbits.com/"&gt;SQLBits&lt;/a&gt; today on ADO.NET Data Services and also to the organisers and community around SQLBits that made the event happen in the first place. I was there for most of the afternoon and it seemed like a fantastic event to me in a cool venue.&lt;/p&gt;  &lt;p&gt;As promised, my slides from the session are &lt;a href="http://mtaulty.com/downloads/MT_DataServices.zip"&gt;here&lt;/a&gt; for download – you’ll perhaps notice that there are a few additional (hidden) slides in the slide-deck that I didn’t use in this talk as I collapsed this talk down from an earlier talk and updated it to reflect the RTM version of Data Services and also the various CTPs/Previews that are currently kicking around.&lt;/p&gt;  &lt;p&gt;So…you get a little more than I actually used at the conference.&lt;/p&gt;  &lt;p&gt;Enjoy :-)&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=11227" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/UKCommunities/default.aspx">UKCommunities</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/DataAccess/default.aspx">DataAccess</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/DataServices/default.aspx">DataServices</category></item><item><title>Astoria Online/Offline</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/10/23/10856.aspx</link><pubDate>Thu, 23 Oct 2008 13:37:39 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10856</guid><dc:creator>mtaulty</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10856</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10856</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/10/23/10856.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/astoriateam/archive/2008/10/22/astoria-futures-offline-enabled-data-services.aspx"&gt;Tantalising&lt;/a&gt; post from the Astoria team.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10856" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/XML/default.aspx">XML</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/WebServices/default.aspx">WebServices</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/EntityFramework/default.aspx">EntityFramework</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/DataAccess/default.aspx">DataAccess</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/DataServices/default.aspx">DataServices</category></item><item><title>DataGrid - Master/Details</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/10/01/10798.aspx</link><pubDate>Wed, 01 Oct 2008 08:38:02 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10798</guid><dc:creator>mtaulty</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10798</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10798</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/10/01/10798.aspx#comments</comments><description>&lt;p&gt;Following on from that previous post about the &lt;a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/09/30/10794.aspx"&gt;WPF DataGrid&lt;/a&gt; I thought it might be interesting to try and move towards more of a master/details view with a separate grid displaying the orders for each customer.&lt;/p&gt; &lt;p&gt;I modified the UI a little bit;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;
  &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="BlogPost.Window1"&lt;/span&gt;
  &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
  &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
  &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="Window1"&lt;/span&gt;
  &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="600"&lt;/span&gt;
  &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="800"&lt;/span&gt;
  &lt;span class="attr"&gt;xmlns:grid&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/wpf/2008/toolkit"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.Resources&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Style&lt;/span&gt;
        &lt;span class="attr"&gt;x:Key&lt;/span&gt;&lt;span class="kwrd"&gt;="myStyle"&lt;/span&gt;
        &lt;span class="attr"&gt;TargetType&lt;/span&gt;&lt;span class="kwrd"&gt;="{x:Type Control}"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt;
          &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Margin"&lt;/span&gt;
          &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="10"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt;
          &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="FontSize"&lt;/span&gt;
          &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="16"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.Resources&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="Auto"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt;
        &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="2*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt;
        &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="2*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="Auto"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBox&lt;/span&gt;
      &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="txtCountry"&lt;/span&gt;
      &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource myStyle}"&lt;/span&gt;      
      &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Country}"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;grid:DataGrid&lt;/span&gt;
      &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="customersGrid"&lt;/span&gt;
      &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;
      &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource myStyle}"&lt;/span&gt;
      &lt;span class="attr"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;
      &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding}"&lt;/span&gt; 
      &lt;span class="attr"&gt;InitializingNewItem&lt;/span&gt;&lt;span class="kwrd"&gt;="OnCustomersGridRowInsert"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;GridSplitter&lt;/span&gt;
      &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Stretch"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;grid:DataGrid&lt;/span&gt;
      &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ordersGrid"&lt;/span&gt;
      &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt;
      &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource myStyle}"&lt;/span&gt;
      &lt;span class="attr"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;
      &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding ElementName=customersGrid,Path=SelectedValue.Orders}"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt;
      &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="3"&lt;/span&gt;
      &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource myStyle}"&lt;/span&gt;
      &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit Changes"&lt;/span&gt;
      &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="OnSubmitChanges"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There's something really simple and really smart going on in the UI. Notice that the second grid ( &lt;strong&gt;ordersGrid&lt;/strong&gt; ) is simply declaratively binding its &lt;strong&gt;ItemsSource&lt;/strong&gt; to the property &lt;strong&gt;SelectedValue.Orders&lt;/strong&gt; of the &lt;strong&gt;customersGrid.&lt;/strong&gt; Pretty smart.&lt;/p&gt;
&lt;p&gt;I also updated the code behind a little bit ( I think I removed one or two functions to make it smaller ) to end up with;&lt;/p&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Window1 : Window, INotifyPropertyChanged
  {
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Window1()
    {
      InitializeComponent();

      &lt;span class="kwrd"&gt;this&lt;/span&gt;.Loaded += OnLoaded;
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnLoaded(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
      &lt;span class="rem"&gt;// Note, letting the orders lazily load.&lt;/span&gt;
      dataContext = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext();

      txtCountry.DataContext = &lt;span class="kwrd"&gt;this&lt;/span&gt;;
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Country 
    {
      get
      {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (country);
      }
      set
      {
        country = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
        Requery();
        FirePropertyChanged(&lt;span class="str"&gt;"Country"&lt;/span&gt;);
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; Requery()
    {
      customersGrid.DataContext = dataContext.Customers.Where(c =&amp;gt; c.Country == txtCountry.Text);
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnCustomersGridRowInsert(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, InitializingNewItemEventArgs e)
    {
      Customer c = e.NewItem &lt;span class="kwrd"&gt;as&lt;/span&gt; Customer;

      &lt;span class="kwrd"&gt;if&lt;/span&gt; (c != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
      {
        c.Country = txtCountry.Text;
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; FirePropertyChanged(&lt;span class="kwrd"&gt;string&lt;/span&gt; property)
    {
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (PropertyChanged != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
      {
        PropertyChanged(&lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedEventArgs(property));
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnSubmitChanges(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs args)
    {
      &lt;span class="rem"&gt;// This needs error handling in the real world.&lt;/span&gt;
      dataContext.SubmitChanges();
    }
    NorthwindDataContext dataContext;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; country;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;
  }
&lt;/pre&gt;
&lt;p&gt;That gives me a working UI in that I can display data;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/DataGridMasterDetails_965F/image.png"&gt;&lt;img border="0" alt="image" src="http://mtaulty.com/blog/images/DataGridMasterDetails_965F/image_thumb.png" width="244" height="184"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;and also, within reason, I can update data. What I mean by "within reason" is that I'm not sure how well this would respond to me changing (e.g.) a foreign key value but then it's perhaps pretty dubious for me to be displaying that to the user in the first place.&lt;/p&gt;
&lt;p&gt;Note that I'm quite happily letting LINQ to SQL do lazy loading on the &lt;strong&gt;Orders&lt;/strong&gt; property of the &lt;strong&gt;Customer&lt;/strong&gt; entity rather than pre-loading all of those orders for the customers.&lt;/p&gt;
&lt;p&gt;I can also go ahead and insert new customers and orders for those customers into this grid - works pretty well in that I can go and create a new customer on that top grid and then add an order to it on that bottom grid by just filling in some value ( the &lt;strong&gt;freight&lt;/strong&gt; in this case );&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/DataGridMasterDetails_965F/image_3.png"&gt;&lt;img border="0" alt="image" src="http://mtaulty.com/blog/images/DataGridMasterDetails_965F/image_thumb_3.png" width="244" height="173"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;and then submit my changes and that works exactly as you'd expect. The interesting thing here is that LINQ to SQL goes ahead and requeries for the &lt;strong&gt;OrderID&lt;/strong&gt; of the inserted order and then the change notification fires and so my new order ID automatically appears on the screen. However, the new &lt;strong&gt;CustomerID&lt;/strong&gt; doesn't appear on there which feels a little strange.&lt;/p&gt;
&lt;p&gt;However, if I navigate to another order ( even before calling SubmitChanges ) and then back again the &lt;strong&gt;CustomerID&lt;/strong&gt; is correctly set as below;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/DataGridMasterDetails_965F/image_4.png"&gt;&lt;img border="0" alt="image" src="http://mtaulty.com/blog/images/DataGridMasterDetails_965F/image_thumb_4.png" width="244" height="173"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;So what's happening there? When we call submit changes we go an do an insert into the &lt;strong&gt;Orders&lt;/strong&gt; table in the database and then LINQ to SQL will requery for the identity column ( orderId ) by using &lt;strong&gt;scope_identity().&lt;/strong&gt; It then sets this on my new order object which causes a property change notification to be fired into the grid which works fine.&lt;/p&gt;
&lt;p&gt;But this is &lt;strong&gt;not&lt;/strong&gt; how the &lt;strong&gt;CustomerID&lt;/strong&gt; is being set on that order. The &lt;strong&gt;CustomerID&lt;/strong&gt; is never set via the property setter. It's set much earlier before we get anywhere near to &lt;strong&gt;SubmitChanges. &lt;/strong&gt;What happens is that the &lt;strong&gt;Customer&lt;/strong&gt; is set on the &lt;strong&gt;Order&lt;/strong&gt; and the generated code goes and sets the &lt;strong&gt;CustomerID&lt;/strong&gt; field but not the property meaning that you don't get property change notification so the grid doesn't update at the time that the &lt;strong&gt;CustomerID&lt;/strong&gt; gets set.&lt;/p&gt;
&lt;p&gt;What I ended up doing was to modify my code a little so that it picks up any inserted order from the &lt;strong&gt;DataGrid&lt;/strong&gt; &lt;strong&gt;InitializingNewItem&lt;/strong&gt; event and it syncs up to any change on the &lt;strong&gt;Customer&lt;/strong&gt; on that newly inserted item and when it detects a change to the &lt;strong&gt;Customer&lt;/strong&gt; it forces the &lt;strong&gt;Order&lt;/strong&gt; to also send a &lt;strong&gt;CustomerID&lt;/strong&gt; property change notification. &lt;/p&gt;
&lt;p&gt;That meant modifying the definition of my &lt;strong&gt;ordersGrid;&lt;/strong&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;grid:DataGrid&lt;/span&gt;
      &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ordersGrid"&lt;/span&gt;
      &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt;
      &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource myStyle}"&lt;/span&gt;
      &lt;span class="attr"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt;
      &lt;span class="attr"&gt;DataContext&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding ElementName=customersGrid,Path=SelectedValue.Orders}"&lt;/span&gt;
      &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding}"&lt;/span&gt;
      &lt;span class="attr"&gt;InitializingNewItem&lt;/span&gt;&lt;span class="kwrd"&gt;="OnOrdersGridRowInsert"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;and then modifying my code behind a little in a few places. I modified the &lt;strong&gt;Order&lt;/strong&gt; class by adding a partial method which will allow me to call its (protected) &lt;strong&gt;SendPropertyChanged&lt;/strong&gt; method;&lt;/p&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Order : INotifyPropertyChanging, INotifyPropertyChanged
  {
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ForcePropertyChanged(&lt;span class="kwrd"&gt;string&lt;/span&gt; property)
    {
      SendPropertyChanged(property);
    }
  }
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and I added a couple of more pieces to my code behind class;&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnOrdersGridRowInsert(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, InitializingNewItemEventArgs e)
    {
      Order o = e.NewItem &lt;span class="kwrd"&gt;as&lt;/span&gt; Order;

      &lt;span class="kwrd"&gt;if&lt;/span&gt; (o != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
      {
        o.PropertyChanged += OnOrderPropertyChanged;
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnOrderPropertyChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, PropertyChangedEventArgs e)
    {
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (e.PropertyName == &lt;span class="str"&gt;"Customer"&lt;/span&gt;)
      {
        Order o = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; Order;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (o != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
          o.ForcePropertyChanged(&lt;span class="str"&gt;"CustomerID"&lt;/span&gt;);
          o.PropertyChanged -= OnOrderPropertyChanged;
        }
      }
    }
&lt;/pre&gt;and now it's all working the way I'd expect with respect to Inserts. I'm not at all sure that this is a "good" way of achieving this, though.
&lt;p&gt;What about deletes? I can select a bunch of orders and delete them and that seems to work just fine and if I delete orders and their corresponding customer then that works as well.&lt;/p&gt;
&lt;p&gt;Where it fails ( as you might expect ) is if I delete a customer without doing anything with the related orders. If I want to make that work then I can modify the code a little. I did this by modifying the UI code - didn't find it quite as easy as I would have liked in that I &lt;strong&gt;&lt;em&gt;seem&lt;/em&gt;&lt;/strong&gt; to have to go down to the route of grabbing an &lt;strong&gt;ICollectionView&lt;/strong&gt; from the &lt;strong&gt;customersGrid&lt;/strong&gt; and then waiting for its &lt;strong&gt;CollectionChanged&lt;/strong&gt; event whereas I was perhaps expecting the &lt;strong&gt;DataGrid&lt;/strong&gt; to have some kind of &lt;strong&gt;Deleted&lt;/strong&gt; event. Here's the code I ended up with;&lt;/p&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Window1 : Window, INotifyPropertyChanged
  {
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Window1()
    {
      InitializeComponent();

      &lt;span class="kwrd"&gt;this&lt;/span&gt;.Loaded += OnLoaded;
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Country 
    {
      get
      {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (country);
      }
      set
      {
        country = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
        Requery();
        FirePropertyChanged(&lt;span class="str"&gt;"Country"&lt;/span&gt;);
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnLoaded(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
      &lt;span class="rem"&gt;// Note, letting the orders lazily load.&lt;/span&gt;
      dataContext = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext();
      txtCountry.DataContext = &lt;span class="kwrd"&gt;this&lt;/span&gt;;
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; Requery()
    {
      customersGrid.DataContext = dataContext.Customers.Where(c =&amp;gt; c.Country == txtCountry.Text);
      ICollectionView colView = CollectionViewSource.GetDefaultView(customersGrid.DataContext);
      colView.CollectionChanged += OnCustomerListModified;
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnCustomerListModified(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (e.Action == NotifyCollectionChangedAction.Remove)
      {
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;object&lt;/span&gt; o &lt;span class="kwrd"&gt;in&lt;/span&gt; e.OldItems)
        {
          Customer c = o &lt;span class="kwrd"&gt;as&lt;/span&gt; Customer;

          &lt;span class="kwrd"&gt;if&lt;/span&gt; ((c != &lt;span class="kwrd"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; (c.Orders != &lt;span class="kwrd"&gt;null&lt;/span&gt;))
          {
            dataContext.Orders.DeleteAllOnSubmit(c.Orders);
          }
        }
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnCustomersGridRowInsert(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, InitializingNewItemEventArgs e)
    {
      Customer c = e.NewItem &lt;span class="kwrd"&gt;as&lt;/span&gt; Customer;

      &lt;span class="kwrd"&gt;if&lt;/span&gt; (c != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
      {
        c.Country = txtCountry.Text;
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnOrdersGridRowInsert(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, InitializingNewItemEventArgs e)
    {
      Order o = e.NewItem &lt;span class="kwrd"&gt;as&lt;/span&gt; Order;

      &lt;span class="kwrd"&gt;if&lt;/span&gt; (o != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
      {
        o.PropertyChanged += OnOrderPropertyChanged;
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnOrderPropertyChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, PropertyChangedEventArgs e)
    {
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (e.PropertyName == &lt;span class="str"&gt;"Customer"&lt;/span&gt;)
      {
        Order o = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; Order;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (o != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
          o.ForcePropertyChanged(&lt;span class="str"&gt;"CustomerID"&lt;/span&gt;);
          o.PropertyChanged -= OnOrderPropertyChanged;
        }
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; FirePropertyChanged(&lt;span class="kwrd"&gt;string&lt;/span&gt; property)
    {
      &lt;span class="kwrd"&gt;if&lt;/span&gt; (PropertyChanged != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
      {
        PropertyChanged(&lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedEventArgs(property));
      }
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; OnSubmitChanges(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs args)
    {
      &lt;span class="rem"&gt;// This needs error handling in the real world.&lt;/span&gt;
      dataContext.SubmitChanges();      
    }
    NorthwindDataContext dataContext;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; country;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;
  }
&lt;/pre&gt;
&lt;p&gt;and, in fact, here's the &lt;a href="http://mtaulty.com/downloads/WpfDataGridMasterDetail.zip"&gt;whole project for download should you want the source code&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10798" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/WPF/default.aspx">WPF</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category></item><item><title>Messing with Dynamic LINQ Queries</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/09/11/10745.aspx</link><pubDate>Thu, 11 Sep 2008 08:08:13 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10745</guid><dc:creator>mtaulty</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10745</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10745</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/09/11/10745.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/mikeormond/"&gt;Mike&lt;/a&gt; was chatting to me about how you'd take something like this ( against LINQ to SQL and the Northwind database );&lt;/p&gt;&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext() { Log = Console.Out })
      {
        &lt;span class="kwrd"&gt;string&lt;/span&gt;[] values = { &lt;span class="str"&gt;"A"&lt;/span&gt;, &lt;span class="str"&gt;"B"&lt;/span&gt;, &lt;span class="str"&gt;"C"&lt;/span&gt; };

        var query =
          from c &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Customers
          select c;

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; s &lt;span class="kwrd"&gt;in&lt;/span&gt; values)
        {
          &lt;span class="kwrd"&gt;string&lt;/span&gt; t = s; &lt;span class="rem"&gt;// Care to avoid capturing the same value 3 times...&lt;/span&gt;
          query = query.Where(c =&amp;gt; c.CompanyName.Contains(t));
        }
        query.ToList();  
      }
      Console.ReadLine();&lt;/pre&gt;
&lt;p&gt;which produces;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactT&lt;br&gt;itle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Coun&lt;br&gt;try], [t0].[Phone], [t0].[Fax]&lt;br&gt;FROM [dbo].[Customers] AS [t0]&lt;br&gt;WHERE ([t0].[CompanyName] LIKE @p0) AND ([t0].[CompanyName] LIKE @p1) AND ([t0].&lt;br&gt;[CompanyName] LIKE @p2)&lt;br&gt;-- @p0: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%C%]&lt;br&gt;-- @p1: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%B%]&lt;br&gt;-- @p2: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%A%]&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;and write a new extension method &lt;strong&gt;Where&lt;/strong&gt; which could take the list of arguments ("A", "B", "C") and a single Lambda and just "figure it out".&lt;/p&gt;
&lt;p&gt;I spent ages on this writing reams of code but in the end I think I chopped it down to;&lt;/p&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; QueryExtensions
  {
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IQueryable&amp;lt;T&amp;gt; Where&amp;lt;T,S&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; IQueryable&amp;lt;T&amp;gt; query, 
      Expression&amp;lt;Func&amp;lt;T,S,&lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; func, &lt;span class="kwrd"&gt;params&lt;/span&gt; S[] args)
    {      
      &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (S s &lt;span class="kwrd"&gt;in&lt;/span&gt; args)
      {
        MethodCallExpression mce = func.Body &lt;span class="kwrd"&gt;as&lt;/span&gt; MethodCallExpression;
        Expression e = MethodCallExpression.Call(mce.Object, mce.Method, Expression.Constant(s));
        query = query.Where&amp;lt;T&amp;gt;(Expression.Lambda&amp;lt;Func&amp;lt;T, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt;(e, func.Parameters[0]));
      }
      &lt;span class="kwrd"&gt;return&lt;/span&gt; (query);
    }
  }&lt;/pre&gt;
&lt;p&gt;and all I'm really attempting to do there is to take the Expression which will have 2 parameters and reduce it down to an Expression which has 1 parameter by hard-wiring the 2nd parameter with the current value of the loop variable "s" into the method call expression itself as a constant. Note sure if that's quite right but I can then use it as;&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext() { Log = Console.Out })
      {
        var query =
          from c &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Customers.Where( (c, s) =&amp;gt; c.CompanyName.Contains(s), &lt;span class="str"&gt;"A"&lt;/span&gt;, &lt;span class="str"&gt;"B"&lt;/span&gt;, &lt;span class="str"&gt;"C"&lt;/span&gt;)
          select c;

        query.ToList();  
      }
      Console.ReadLine();
&lt;/pre&gt;
&lt;p&gt;which seems to produce;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactT&lt;br&gt;itle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Coun&lt;br&gt;try], [t0].[Phone], [t0].[Fax]&lt;br&gt;FROM [dbo].[Customers] AS [t0]&lt;br&gt;WHERE ([t0].[CompanyName] LIKE @p0) AND ([t0].[CompanyName] LIKE @p1) AND ([t0].&lt;br&gt;[CompanyName] LIKE @p2)&lt;br&gt;-- @p0: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%C%]&lt;br&gt;-- @p1: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%B%]&lt;br&gt;-- @p2: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%A%]&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;which &lt;em&gt;looks&lt;/em&gt; alright. I'm not sure that it's universally useful in that &lt;strong&gt;Where&lt;/strong&gt; is basically &lt;strong&gt;AndWhere&lt;/strong&gt; so whilst &lt;strong&gt;Contains&lt;/strong&gt; might work here there perhaps aren't that many other methods that would make sense. 
&lt;p&gt;Regardless, it took me quite a while and I still don't really understand building dynamic expressions at all properly :-)
&lt;p&gt;Some older bits about dynamic queries and the such like;
&lt;blockquote&gt;
&lt;p&gt;&lt;a title="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/11/10/9911.aspx" href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/11/10/9911.aspx"&gt;http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/11/10/9911.aspx&lt;/a&gt;
&lt;p&gt;&lt;a title="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/15/9489.aspx" href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/15/9489.aspx"&gt;http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/15/9489.aspx&lt;/a&gt;
&lt;p&gt;&lt;a title="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/18/9490.aspx" href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/18/9490.aspx"&gt;http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/18/9490.aspx&lt;/a&gt;
&lt;p&gt;&lt;a title="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/18/9492.aspx" href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/18/9492.aspx"&gt;http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/06/18/9492.aspx&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10745" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category></item><item><title>SQL 2008, Filestream, Docs from VB</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/09/08/10729.aspx</link><pubDate>Mon, 08 Sep 2008 06:56:45 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10729</guid><dc:creator>mtaulty</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10729</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10729</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/09/08/10729.aspx#comments</comments><description>&lt;p&gt;Someone asked me if I had a simple sample of how to read/write documents into a database table using FILESTREAM in SQL Server 2008.&lt;/p&gt; &lt;p&gt;I set about it.&lt;/p&gt; &lt;p&gt;Firstly, I had to find out how to switch FILESTREAM on in the RTM of SQL Server. At times like this you need &lt;a href="http://www.sqlskills.com/blogs/bobb/2008/02/28/ConfiguringFilestreamInCTP6ItsDifferent.aspx"&gt;Bob Beauchemin&lt;/a&gt; to tell you how it's done and then you can go and run code such as this once you've done the necessary bits in SQL Configuration manager;&lt;/p&gt;&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;exec&lt;/span&gt; sp_configure filestream_access_level, 2
&lt;span class="kwrd"&gt;reconfigure&lt;/span&gt;
&lt;span class="kwrd"&gt;go&lt;/span&gt;

&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;DATABASE&lt;/span&gt; Documents 
&lt;span class="kwrd"&gt;ON&lt;/span&gt;
&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; 
( 
    NAME = DocData,
    FILENAME = &lt;span class="str"&gt;'c:\temp\docs.mdf'&lt;/span&gt;
),
FILEGROUP FileGroup &lt;span class="kwrd"&gt;CONTAINS&lt;/span&gt; FILESTREAM
( 
    NAME = DocFiles,
    FILENAME = &lt;span class="str"&gt;'c:\temp\docstreams'&lt;/span&gt;
)
LOG &lt;span class="kwrd"&gt;ON&lt;/span&gt;  
( 
    NAME = DocLog,
    FILENAME = &lt;span class="str"&gt;'c:\temp\docs.ldf'&lt;/span&gt;
)
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;/pre&gt;
&lt;p&gt;and now I've got a database that can accept file stream data. Phew. Time for a simple table;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;create&lt;/span&gt; &lt;span class="kwrd"&gt;table&lt;/span&gt; Docs
(
    id uniqueidentifier &lt;span class="kwrd"&gt;rowguidcol&lt;/span&gt; &lt;span class="kwrd"&gt;not&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt; &lt;span class="kwrd"&gt;primary&lt;/span&gt; &lt;span class="kwrd"&gt;key&lt;/span&gt;,
    documentData varbinary(&lt;span class="kwrd"&gt;max&lt;/span&gt;) filestream &lt;span class="kwrd"&gt;not&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;,
    documentName nvarchar(1024) &lt;span class="kwrd"&gt;not&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;
)&lt;/pre&gt;
&lt;p&gt;Now I've got a table I can use something like Windows Presentation Foundation with VB to build a simple UI to allow me to add documents to the database and then edit them. Note that editing them here just means sucking out the file data, writing it to a temporary file, passing that to the Shell for editing and then saving the contents back to the database.&lt;/p&gt;
&lt;p&gt;There ended up being too much code to paste in here as a blow-by-blow account but here's my rather grey looking UI;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/SQL2008FilestreamDocsfromVB_E020/image.png"&gt;&lt;img border="0" alt="image" src="http://mtaulty.com/blog/images/SQL2008FilestreamDocsfromVB_E020/image_thumb.png" width="434" height="484"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;with a few items from my desktop that I've added to my database table.&lt;/p&gt;
&lt;p&gt;The code's pretty hacky with almost no error handling but I thought I'd &lt;a href="http://mtaulty.com/downloads/VBDocumentClient.zip"&gt;share it here for download regardless&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10729" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/VB/default.aspx">VB</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/WPF/default.aspx">WPF</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category></item><item><title>On LINQ to SQL, Concurrency and Timestamps</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/07/01/10557.aspx</link><pubDate>Tue, 01 Jul 2008 14:10:31 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10557</guid><dc:creator>mtaulty</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10557</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10557</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/07/01/10557.aspx#comments</comments><description>&lt;p&gt;I came across a bit of a glitch in using timestamps for checking concurrency violations in LINQ to SQL and thought I'd share.&lt;/p&gt; &lt;p&gt;Say I've got a table like;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;create&lt;/span&gt; &lt;span class="kwrd"&gt;table&lt;/span&gt; Person
(
  id &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;identity&lt;/span&gt; &lt;span class="kwrd"&gt;primary&lt;/span&gt; &lt;span class="kwrd"&gt;key&lt;/span&gt;,
  firstName nvarchar(30),
  lastName nvarchar(30),
  &lt;span class="kwrd"&gt;timestamp&lt;/span&gt; 
)&lt;/pre&gt;
&lt;p&gt;so, we have a simple table that has a timestamp on it and I want to use that to detect any concurrency problems that I might have in LINQ to SQL.&lt;/p&gt;
&lt;p&gt;Let's populate this table with some data;&lt;/p&gt;&lt;pre class="csharpcode"&gt;insert person(firstname,lastname) values(&lt;span class="str"&gt;'first1'&lt;/span&gt;, &lt;span class="str"&gt;'last1'&lt;/span&gt;)
insert person(firstname,lastname) values(&lt;span class="str"&gt;'first2'&lt;/span&gt;, &lt;span class="str"&gt;'last2'&lt;/span&gt;)
insert person(firstname,lastname) values(&lt;span class="str"&gt;'first3'&lt;/span&gt;, &lt;span class="str"&gt;'last3'&lt;/span&gt;)&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and then I can bring that into my LINQ to SQL environment and I can check what the concurrency options are set to;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/OnLINQtoSQLConcurrencyandTimestamps_1319A/image.png"&gt;&lt;img height="361" alt="image" src="http://mtaulty.com/blog/images/OnLINQtoSQLConcurrencyandTimestamps_1319A/image_thumb.png" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;So, you can see that we've got &lt;strong&gt;Update Check&lt;/strong&gt; set to &lt;strong&gt;Always&lt;/strong&gt; and that means that the timestamp will be added to any where clauses for Deletes or Updates and if a particular update doesn't find any row to update because of that where clause then we have a concurrency violation.&lt;/p&gt;
&lt;p&gt;Note also that &lt;strong&gt;Auto-Sync&lt;/strong&gt; is set to &lt;strong&gt;Always&lt;/strong&gt; which is a good thing because it means that if we insert an entity we'll automatically get the timestamp back and if we update an entity we'll similarly get an updated timestamp so that the timestamp in the &lt;strong&gt;&lt;em&gt;original values&lt;/em&gt;&lt;/strong&gt; of our entity in memory will represent the timestamp of the record when we queried/inserted/updated it and will only get "stale" if someone else were to update it (or delete it) in the meantime.&lt;/p&gt;
&lt;p&gt;So, with LINQ to SQL we can write some code such as the stuff below which prompts for a new surname, changes the value in the entities that it has queried then tries to do a &lt;strong&gt;SubmitChanges&lt;/strong&gt; and tries to make sure that it captures as many concurrency violations as it can ( the &lt;strong&gt;ContinueOnConflict&lt;/strong&gt; parameter ).&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;using&lt;/span&gt; (DemoDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; DemoDataContext())
    {
      var people = ctx.Persons.ToList();

      Console.WriteLine(&lt;span class="str"&gt;"Enter a new surname"&lt;/span&gt;);
      &lt;span class="kwrd"&gt;string&lt;/span&gt; surname = Console.ReadLine();

      &lt;span class="rem"&gt;// Cause some changes.&lt;/span&gt;
      &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Person p &lt;span class="kwrd"&gt;in&lt;/span&gt; people)
      {
        p.lastName = surname;
      }
      &lt;span class="rem"&gt;// HERE...&lt;/span&gt;
      Console.WriteLine(&lt;span class="str"&gt;"Now's the time to cause a concurrency violation"&lt;/span&gt;);
      Console.ReadLine();

      &lt;span class="kwrd"&gt;bool&lt;/span&gt; allSaved = &lt;span class="kwrd"&gt;false&lt;/span&gt;;

      &lt;span class="kwrd"&gt;while&lt;/span&gt; (!allSaved)
      {
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
          ctx.SubmitChanges(ConflictMode.ContinueOnConflict);
          allSaved = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (ChangeConflictException ex)
        {
          Console.WriteLine(&lt;span class="str"&gt;"Hit a conflict - fixing it!"&lt;/span&gt;);

          &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (ObjectChangeConflict conflict &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.ChangeConflicts)
          {
            conflict.Resolve(RefreshMode.KeepChanges);
          }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
          Console.WriteLine(&lt;span class="str"&gt;"Hit an unexpected exception [{0}]"&lt;/span&gt;,
            ex.Message);
        }
      }
    }&lt;/pre&gt;
&lt;p&gt;When we hit the line of code marked &lt;strong&gt;HERE&lt;/strong&gt; above, I go and run this piece of T-SQL;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;update&lt;/span&gt; person &lt;span class="kwrd"&gt;set&lt;/span&gt; lastName=&lt;span class="str"&gt;'anything'&lt;/span&gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; id=2
&lt;span class="kwrd"&gt;update&lt;/span&gt; person &lt;span class="kwrd"&gt;set&lt;/span&gt; lastName=&lt;span class="str"&gt;'else'&lt;/span&gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; id=3&lt;/pre&gt;
&lt;p&gt;to cause concurrency problems for row number 2 and number 3 in my database.&lt;/p&gt;
&lt;p&gt;What &lt;em&gt;should&lt;/em&gt; happen;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We read 3 entities with timestamps T1, T2, T3. 
&lt;li&gt;We modify the surnames in our code. 
&lt;li&gt;We use T-SQL to modify the timestamps T2, T3 in the database to ( say ) TM2 and TM3. 
&lt;li&gt;We submit our changes. 
&lt;li&gt;Our modifications for entities 2 and 3 will fail because T2!=TM2 and T3!=TM3. Our transaction is rolled back. 
&lt;li&gt;We use &lt;strong&gt;Resolve&lt;/strong&gt; in order to keep any changes that we have made in our code ( i.e. the surname modification ) but to refresh the other entity values from the DB. 
&lt;li&gt;We now have in our program entities with timestamps T1, TM2, TM3 
&lt;li&gt;We submit our changes. 
&lt;li&gt;The code completes.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;However, that's not what happens when the code does. What happens is that we hit an unexpected exception at &lt;strong&gt;8&lt;/strong&gt; above and my &lt;strong&gt;Console.WriteLine&lt;/strong&gt; writes it out;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Hit an unexpected exception [Value of member 'timestamp' of an object of type 'Person' changed.&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;What's going on here? I &lt;em&gt;think&lt;/em&gt; what's happening here is that when we hit the call to &lt;strong&gt;SubmitChanges&lt;/strong&gt; we go to the database to update 3 entities. The first update works so we update the timestamp. The 2nd update fails and so does the 3rd so we rollback the transaction. 
&lt;p&gt;&lt;strong&gt;However, we've updated the timestamp on that 1st entity&lt;/strong&gt;. 
&lt;p&gt;We then go and resolve the 2 concurrency violations we've got before calling &lt;strong&gt;SubmitChanges&lt;/strong&gt; again. It takes a look at that first entity which didn't have a concurrency problem but &lt;em&gt;does &lt;/em&gt;now have a modified timestamp and still needs updating in the database ( because the transaction was rolled back ) and says &lt;strong&gt;"Hey, you're not meant to change generated columns like this!!".&lt;/strong&gt; 
&lt;p&gt;Got it? 
&lt;h5&gt;Option - Stop LINQ to SQL from Updating the TimeStamp Automatically on Update&lt;/h5&gt;
&lt;p&gt;The timestamp is only being updated because we have allowed the &lt;strong&gt;Auto-Sync&lt;/strong&gt; property to be default to &lt;strong&gt;Always&lt;/strong&gt; in the mapping information. That means "re-sync this column whenever we insert, update".&lt;/p&gt;
&lt;p&gt;We could change this so that we only do &lt;strong&gt;Auto-Sync&lt;/strong&gt; on &lt;strong&gt;Insert&lt;/strong&gt; by setting;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/OnLINQtoSQLConcurrencyandTimestamps_1319A/image_3.png"&gt;&lt;img height="375" alt="image" src="http://mtaulty.com/blog/images/OnLINQtoSQLConcurrencyandTimestamps_1319A/image_thumb_3.png" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Now, our code as it originally stands is going to work just fine if I re-run it under the same conditions where I cause a concurrency violation at the line marked &lt;strong&gt;HERE &lt;/strong&gt;because when we hit the initial call to &lt;strong&gt;SubmitChanges&lt;/strong&gt; which throws a &lt;strong&gt;ChangeConflictException&lt;/strong&gt; we catch that exception, call &lt;strong&gt;Resolve&lt;/strong&gt; on the 2 rows with the problems and then we call &lt;strong&gt;SubmitChanges&lt;/strong&gt; again and we've never updated the timestamp on row number 1.&lt;/p&gt;
&lt;p&gt;However...this isn't a free ride.&lt;/p&gt;
&lt;p&gt;The problem with switching &lt;strong&gt;Auto-Sync&lt;/strong&gt; to &lt;strong&gt;OnInsert&lt;/strong&gt; means that whenever we actually do a successful update we &lt;em&gt;won't&lt;/em&gt; update the timestamp to reflect the latest value that we just generated in the database.&lt;/p&gt;
&lt;p&gt;So, whenever we call &lt;strong&gt;SubmitChanges&lt;/strong&gt; for subsequent updates we will see superfluous concurrency exceptions for every row that &lt;em&gt;didn't&lt;/em&gt; hit a concurrency exception the last time we called &lt;strong&gt;SubmitChanges.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That is, this code (which runs forever) will &lt;em&gt;work&lt;/em&gt;;&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;using&lt;/span&gt; (DemoDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; DemoDataContext())
    {
      var people = ctx.Persons.ToList();

      &lt;span class="kwrd"&gt;while&lt;/span&gt; (&lt;span class="kwrd"&gt;true&lt;/span&gt;)
      {
        Console.WriteLine(&lt;span class="str"&gt;"Enter a new surname"&lt;/span&gt;);
        &lt;span class="kwrd"&gt;string&lt;/span&gt; surname = Console.ReadLine();

        &lt;span class="rem"&gt;// Cause some changes.&lt;/span&gt;
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Person p &lt;span class="kwrd"&gt;in&lt;/span&gt; people)
        {
          p.lastName = surname;
        }
        &lt;span class="rem"&gt;// HERE...&lt;/span&gt;
        Console.WriteLine(&lt;span class="str"&gt;"Now's the time to cause a concurrency violation"&lt;/span&gt;);
        Console.ReadLine();

        &lt;span class="kwrd"&gt;bool&lt;/span&gt; allSaved = &lt;span class="kwrd"&gt;false&lt;/span&gt;;

        &lt;span class="kwrd"&gt;while&lt;/span&gt; (!allSaved)
        {
          &lt;span class="kwrd"&gt;try&lt;/span&gt;
          {
            ctx.SubmitChanges(ConflictMode.ContinueOnConflict);
            Console.WriteLine(&lt;span class="str"&gt;"Submitted changes"&lt;/span&gt;);
            allSaved = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
          }
          &lt;span class="kwrd"&gt;catch&lt;/span&gt; (ChangeConflictException ex)
          {
            Console.WriteLine(&lt;span class="str"&gt;"Hit a conflict - fixing it!"&lt;/span&gt;);

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (ObjectChangeConflict conflict &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.ChangeConflicts)
            {
              conflict.Resolve(RefreshMode.KeepChanges);
            }
          }
          &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
          {
            Console.WriteLine(&lt;span class="str"&gt;"Hit an unexpected exception [{0}]"&lt;/span&gt;,
              ex.Message);
          }
        }
      }
    }
&lt;/pre&gt;
&lt;p&gt;and it'll work regardless of whether I cause concurrency problems at the line marked &lt;strong&gt;HERE. &lt;/strong&gt;However, once the loop has executed once we run the risk of hitting "false" concurrency problems at the call to &lt;strong&gt;SubmitChanges&lt;/strong&gt; for any rows that have out of date timestamps because we did not update them the last time we did an update.&lt;/p&gt;
&lt;p&gt;The other thing that comes to mind here is that this all depends on the &lt;strong&gt;&lt;a href="http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx"&gt;lifetime of your DataContext&lt;/a&gt;. &lt;/strong&gt;If you just use it for one "unit of work" then this isn't really going to bite you in the same way because &lt;strong&gt;Auto-Sync&lt;/strong&gt; doesn't seem so relevant if you're going to throw your &lt;strong&gt;DataContext&lt;/strong&gt; away after you call &lt;strong&gt;SubmitChanges&lt;/strong&gt; anyway.&lt;/p&gt;
&lt;p&gt;And the last thing is that this won't affect you at all unless you're using generated columns like timestamps for concurrency checking.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10557" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/.NET/default.aspx">.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/DataAccess/default.aspx">DataAccess</category></item><item><title>Michael Rys in London on Non-Relational Data in SQL Server</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/06/25/10537.aspx</link><pubDate>Wed, 25 Jun 2008 06:51:36 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10537</guid><dc:creator>mtaulty</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10537</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10537</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/06/25/10537.aspx#comments</comments><description>&lt;p&gt;The UK, SQL Server User Group has &lt;a href="http://blogs.msdn.com/mrys/"&gt;Michael Rys&lt;/a&gt; delivering a talk on Monday in London. Michael's a Program Manager in SQL Server.&lt;/p&gt; &lt;p&gt;&lt;a href="http://sqlserverfaq.com/?eid=126"&gt;Go here for the details&lt;/a&gt; and to sign up.&lt;/p&gt; &lt;p&gt;I don't know Michael personally but I know that back when I was looking at SQL Server 2005 and I asked any kind of question about the new XML data type it was more-often-than-not an email that came back from Michael with the answer in it so you should be in for a treat if you manage to get yourself signed up for this.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10537" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/UKCommunities/default.aspx">UKCommunities</category></item><item><title>"When Do Queries Execute"</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/05/21/10433.aspx</link><pubDate>Wed, 21 May 2008 06:18:17 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10433</guid><dc:creator>mtaulty</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10433</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10433</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/05/21/10433.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.thedatafarm.com/blog/2008/05/20/CommandExecutionOfDirectlyCalledImportFunctionsStoredProcsInEntityFramework.aspx"&gt;Julie's got a great post about when stored procedures execute when using LINQ to Entities&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;It made me think about &lt;strong&gt;LINQ to SQL&lt;/strong&gt; where if I've got something like;&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext())
      {
        var query = ctx.GetCustomersByCountry(&lt;span class="str"&gt;"UK"&lt;/span&gt;); &lt;span class="rem"&gt;// SQL Happens Here!&lt;/span&gt;

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Customer c &lt;span class="kwrd"&gt;in&lt;/span&gt; query)
        {
          Console.WriteLine(c.CustomerID );
        }
      }&lt;/pre&gt;
&lt;p&gt;Then we see the same effect as Julie's seeing in LINQ to Entities (note &lt;strong&gt;GetCustomersByCountry&lt;/strong&gt; is a stored procedure) whereas if I've got something like;&lt;/p&gt;&lt;pre class="csharpcode"&gt;     &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext())
      {
        var query = ctx.FnGetCustomersByCountry(&lt;span class="str"&gt;"UK"&lt;/span&gt;); 

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Customer c &lt;span class="kwrd"&gt;in&lt;/span&gt; query) &lt;span class="rem"&gt;// SQL Happens Here&lt;/span&gt;
        {
          Console.WriteLine(c.CustomerID );
        }
      }&lt;/pre&gt;
&lt;p&gt;where &lt;strong&gt;FnGetCustomersByCountry&lt;/strong&gt; is a table-valued function then the query is executed at a different point in time. &lt;/p&gt;
&lt;p&gt;I guess one reason for this is that table-valued functions are composable in LINQ to SQL so I can do something like;&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext())
      {
        var query = ctx.FnGetCustomersByCountry(&lt;span class="str"&gt;"UK"&lt;/span&gt;);

        query =
          from c &lt;span class="kwrd"&gt;in&lt;/span&gt; query
          &lt;span class="kwrd"&gt;where&lt;/span&gt; c.CustomerID.StartsWith(&lt;span class="str"&gt;"B"&lt;/span&gt;)
          select c;

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Customer c &lt;span class="kwrd"&gt;in&lt;/span&gt; query) &lt;span class="rem"&gt;// SQL Happens Here&lt;/span&gt;
        {
          Console.WriteLine(c.CustomerID );
        }
      }&lt;/pre&gt;
&lt;p&gt;whereas I can't do that with a stored procedure so maybe it makes sense to execute the stored procedure ASAP as deferring the execution would add no value but ( on the other hand and as Julie says ) it's a bit confusing to the developer who's got used to queries occurring when we enumerate.&lt;/p&gt;
&lt;p&gt;For the table-valued-function case, not to defer the query would be a problem because we'd then be applying the &lt;strong&gt;StartsWith&lt;/strong&gt; clause in memory on the client-side rather than adding it to the query on the server-side.&lt;/p&gt;
&lt;p&gt;If you look at the generated code on the DataContext you see;&lt;/p&gt;&lt;pre class="csharpcode"&gt;    [Function(Name=&lt;span class="str"&gt;"dbo.FnGetCustomersByCountry"&lt;/span&gt;, IsComposable=&lt;span class="kwrd"&gt;true&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IQueryable&amp;lt;Customer&amp;gt; FnGetCustomersByCountry([Parameter(DbType=&lt;span class="str"&gt;"NVarChar(MAX)"&lt;/span&gt;)] &lt;span class="kwrd"&gt;string&lt;/span&gt; country)
    {
      &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.CreateMethodCallQuery&amp;lt;Customer&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;, ((MethodInfo)(MethodInfo.GetCurrentMethod())), country);
    }
    
    [Function(Name=&lt;span class="str"&gt;"dbo.GetCustomersByCountry"&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ISingleResult&amp;lt;Customer&amp;gt; GetCustomersByCountry([Parameter(DbType=&lt;span class="str"&gt;"NVarChar(MAX)"&lt;/span&gt;)] &lt;span class="kwrd"&gt;string&lt;/span&gt; country)
    {
      IExecuteResult result = &lt;span class="kwrd"&gt;this&lt;/span&gt;.ExecuteMethodCall(&lt;span class="kwrd"&gt;this&lt;/span&gt;, ((MethodInfo)(MethodInfo.GetCurrentMethod())), country);
      &lt;span class="kwrd"&gt;return&lt;/span&gt; ((ISingleResult&amp;lt;Customer&amp;gt;)(result.ReturnValue));
    }&lt;/pre&gt;
&lt;p&gt;so on the one hand we have &lt;strong&gt;CreateMethodCallQuery &lt;/strong&gt;and on the other we have &lt;strong&gt;ExecuteMethodCall &lt;/strong&gt;and, just to be devious, I wondered if I could do a cheap hack here and try and get deferred execution of my stored procedure just by trying to use &lt;strong&gt;CreateMethodCallQuery&lt;/strong&gt; but I didn't manage to get that going yet - clearly, there'd be other ways of achieving the same thing.&lt;/p&gt;
&lt;p&gt;Finally, there's also the question of when the data reader is actually read from the wire when you're doing this kind of work which I talked about a little &lt;a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/13/10236.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10433" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category></item><item><title>Mocking LINQ to SQL</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/05/09/10392.aspx</link><pubDate>Fri, 09 May 2008 07:21:13 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10392</guid><dc:creator>mtaulty</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10392</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10392</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/05/09/10392.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/mattwar/archive/2008/05/04/mocks-nix-an-extensible-linq-to-sql-datacontext.aspx"&gt;Matt Warren has an "interesting" post on how you could hack your way to a mocked implementation of LINQ to SQL&lt;/a&gt; - if I had a pound for every time someone's asked me how to do this then I'd have at least 3 pounds :-)&lt;/p&gt; &lt;p&gt;Seriously though, there is interest in doing this kind of thing and it's a good starting place if you're inclined to head down this route.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10392" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category></item><item><title>LINQ to SQL and SqlConnection ( "when you're wrong, you're wrong" :-) )</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/20/10257.aspx</link><pubDate>Thu, 20 Mar 2008 08:56:10 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10257</guid><dc:creator>mtaulty</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10257</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10257</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/20/10257.aspx#comments</comments><description>&lt;p&gt;I was talking to &lt;a href="http://codebetter.com/blogs/ian_cooper/"&gt;Ian&lt;/a&gt; and another chap at the UK Launch yesterday about LINQ to SQL and my use of the DataContext in some demo code where I always tend to write something like;&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;using&lt;/span&gt; (DataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataContext())
      {
      }&lt;/pre&gt;
&lt;p&gt;and whether I actually needed to do that dispose or not?&lt;/p&gt;
&lt;p&gt;Now...I was pretty confident that I do need to do this for two reasons;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;DataContext is disposable so I figure I should probably Dispose() of it - generally been my approach to anything &lt;strong&gt;IDisposable.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Someone had recently asked me whether DataContext.Dispose() actually did close the SQL connection and I'd done a little bit of reflecting on it and spotted that;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;DataContext.Dispose() -&amp;gt; SqlProvider.Dispose() -&amp;gt; SqlConnectionManager.DisposeConnection() -&amp;gt; SqlConnection.Close()&lt;/li&gt;&lt;/ol&gt;&lt;/ol&gt;
&lt;p&gt;although the code paths are more complex than that and I haven't attempted to figure out under what conditions the various calls happen.&lt;/p&gt;
&lt;p&gt;So, I'd kind of reasoned that;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If you don't dispose of the DataContext then you won't get the connection closed and back in the pool until finalisation time which is generally a bad idea.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;but then I started to wonder whether that assumption was right and it turns out that it isn't really right but then it's not exactly wrong either :-) &lt;/p&gt;
&lt;p&gt;So, to test this all out I did a bit of debugging and wrote;&lt;/p&gt;&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext())
      {
        (from c &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Customers select c).ToList();

        (from c &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Customers select c).ToList();

        (from c &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Customers select c).ToList();
      }&lt;/pre&gt;
&lt;p&gt;and ran it under the debugger with breakpoints in &lt;strong&gt;SqlConnection.Open()&lt;/strong&gt; and &lt;strong&gt;SqlConnection.Close()&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I was foxed for a while because I see 5 calls to Open() and 5 calls to Close(). I was expecting either;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;1 call to Open and 1 to Close.&lt;/li&gt;
&lt;li&gt;3 calls to Open and 3 to Close.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;A quick look at the call-stacks showed that it seems like when we hit the first query to be evaluated we first do;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image.png"&gt;&lt;img height="100" alt="image" src="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image_thumb.png" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;which looks like we're opening the connection in order to test if it's SQLCE or not. Then we see a Close followed by;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image_3.png"&gt;&lt;img height="129" alt="image" src="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image_thumb_3.png" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;So...a similar check to see if it's SQL 2000 or earlier followed by a Close.&lt;/p&gt;
&lt;p&gt;So...following that I see an &lt;strong&gt;Open/Close&lt;/strong&gt; pairing around each query that I execute which suggests that, in an ideal world, there'd be no need to dispose of the context because the connection is being opened/closed on demand every time we do a query. The &lt;strong&gt;Close&lt;/strong&gt; calls that I see are coming from;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image_4.png"&gt;&lt;img height="108" alt="image" src="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image_thumb_4.png" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;That is - they are &lt;em&gt;not&lt;/em&gt; coming from &lt;strong&gt;Dispose&lt;/strong&gt; on the &lt;strong&gt;DataContext &lt;/strong&gt;but, instead, they are coming from the &lt;strong&gt;Dispose&lt;/strong&gt; on the &lt;strong&gt;ObjectReaderCompiler.ObjectReader&lt;/strong&gt;. Who he?&lt;/p&gt;
&lt;p&gt;Well, it looks like he's the &lt;strong&gt;IEnumerator &lt;/strong&gt;that's returned for my &lt;strong&gt;foreach&lt;/strong&gt; iteration and he's &lt;strong&gt;IDisposable&lt;/strong&gt; so if he gets disposed (i.e. when you've read all the data) then he closes the connection. He's getting disposed here because &lt;strong&gt;foreach&lt;/strong&gt; is being friendly but it's not hard to come up with a situation where that might not happen;&lt;/p&gt;
&lt;p&gt;So...I should be able to defeat that with something that leaves the enumerator kicking around like;&lt;/p&gt;&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindDataContext ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindDataContext())
      {
        var query = from c &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Customers
                    select c;

        var enumerator = query.GetEnumerator();
      }&lt;/pre&gt;
&lt;p&gt;and I finally see the &lt;strong&gt;DataContext&lt;/strong&gt; stepping in and disposing and ultimately closing the connection;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image_5.png"&gt;&lt;img height="160" alt="image" src="http://mtaulty.com/blog/images/LINQtoSQLandSqlConnectionwhenyourewrongy_D39F/image_thumb_5.png" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Now, arguably I should be &lt;strong&gt;disposing&lt;/strong&gt; of the &lt;strong&gt;enumerator&lt;/strong&gt; here and that's solve the problem of the open connection again but really that just goes back to the original idea which is "if it's disposable, dispose it" so I've really just moved the decision from one disposable type to another.&lt;/p&gt;
&lt;p&gt;Additionally, I'd imagine that there are lots of other places where not disposing the DataContext could mean that you wait until a finalizer runs in order to get a connection back into the pool so it feels like the right thing to do is always to Dispose() to be safe rather than sorry.&lt;/p&gt;
&lt;p&gt;There's a FAQ up here about LINQ to SQL;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/bb386929.aspx" href="http://msdn2.microsoft.com/en-us/library/bb386929.aspx"&gt;http://msdn2.microsoft.com/en-us/library/bb386929.aspx&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;which has a section in it about the lifetime of connections so that'd be the right place to go for a definitive answer.&lt;/p&gt;
&lt;p&gt;I like simple things so I'm going to stick with my basic law of "If it's disposable, dispose of it" :-) &lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10257" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category></item><item><title>LINQ to SQL, Stored Procs, Output Params, Readers Reading</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/13/10236.aspx</link><pubDate>Thu, 13 Mar 2008 15:31:43 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10236</guid><dc:creator>mtaulty</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10236</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10236</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/13/10236.aspx#comments</comments><description>&lt;p&gt;I had a discussion at &lt;a href="http://www.devweek.com"&gt;DevWeek&lt;/a&gt; about when &lt;strong&gt;SqlDataReader.Read&lt;/strong&gt;() gets called for resultsets coming back from stored procedures accessed with LINQ to SQL.&lt;/p&gt; &lt;p&gt;I've got this stored proc;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;create&lt;/span&gt; &lt;span class="kwrd"&gt;procedure&lt;/span&gt; dbo.GetCustomersByCountry  
 @country nvarchar(&lt;span class="kwrd"&gt;max&lt;/span&gt;)  
&lt;span class="kwrd"&gt;as&lt;/span&gt;  
 &lt;span class="kwrd"&gt;set&lt;/span&gt; nocount &lt;span class="kwrd"&gt;on&lt;/span&gt;  
 &lt;span class="kwrd"&gt;select&lt;/span&gt; * &lt;span class="kwrd"&gt;from&lt;/span&gt; dbo.customers  
 &lt;span class="kwrd"&gt;where&lt;/span&gt; country = @country&lt;/pre&gt;
&lt;p&gt;and I've brought it into LINQ to SQL using the designer and that means that I can write code such as;&lt;/p&gt;&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindModelDataContext ctx =
      &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindModelDataContext())
    {
      var query = ctx.GetCustomersByCountry(&lt;span class="str"&gt;"UK"&lt;/span&gt;);

      &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Customer c &lt;span class="kwrd"&gt;in&lt;/span&gt; query)
      {
        Console.WriteLine(c.CustomerID);
      }
    }&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Question is - when does &lt;strong&gt;SqlDataReader.Read()&lt;/strong&gt; get called here? Do we read all of the data up front and then just provide access to an in-memory collection or is the data read from the wire as the loop iterates over it?&lt;/p&gt;
&lt;p&gt;I wanted to check so I went ahead and set some breakpoints in a few places;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Inside the constructor of my &lt;strong&gt;Customer&lt;/strong&gt; class. 
&lt;li&gt;Inside &lt;strong&gt;SqlDataReader.Read()&lt;/strong&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;and what I see there is an interleaved set of calls which go &lt;strong&gt;[Read-&amp;gt;Construct-&amp;gt;Read-&amp;gt;Construct]&lt;/strong&gt; and so the results are being returned as they are read from the wire - i.e. as the foreach loop pulls them out object by object.&lt;/p&gt;
&lt;p&gt;Now, here's another stored procedure;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;create&lt;/span&gt; &lt;span class="kwrd"&gt;procedure&lt;/span&gt; TestOutputProc(  
 @id &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;output&lt;/span&gt;  
)  
&lt;span class="kwrd"&gt;as&lt;/span&gt;  
 &lt;span class="kwrd"&gt;set&lt;/span&gt; nocount &lt;span class="kwrd"&gt;on&lt;/span&gt;  
 &lt;span class="kwrd"&gt;select&lt;/span&gt; * &lt;span class="kwrd"&gt;from&lt;/span&gt; dbo.customers  
 &lt;span class="kwrd"&gt;set&lt;/span&gt; @id = 10&lt;/pre&gt;
&lt;p&gt;This has an output parameter. I bring this into the LINQ to SQL environment and I program against it like this;&lt;/p&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindModelDataContext ctx =
      &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindModelDataContext())
    {
      &lt;span class="kwrd"&gt;int&lt;/span&gt;? x = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

      var query = ctx.TestOutputProc(&lt;span class="kwrd"&gt;ref&lt;/span&gt; x);

      Console.WriteLine(x);

      &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Customer c &lt;span class="kwrd"&gt;in&lt;/span&gt; query)
      {
        Console.WriteLine(c.CustomerID);
      }
    }&lt;/pre&gt;
&lt;p&gt;Notice - the output parameter is available before I've started to enumerate through the query results. If I go and run this under my debugger then what I see is &lt;strong&gt;[Read-&amp;gt;Read-&amp;gt;Read-&amp;gt;Read-&amp;gt; ....] &lt;/strong&gt;and so the entire resultset is read before we get to the &lt;strong&gt;Console.Writeline&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This isn't entirely unexpected - AFAIK you need to read the resultset before you can get to the output parameter and that's what is surfacing inside of LINQ to SQL here. However, it does mean that you need to apply some thought if you're going to return a lot of data from a procedure with an outgoing parameter.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10236" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/DataAccess/default.aspx">DataAccess</category></item><item><title>ADO.NET Entity Framework - QueryViews, Inline Functions in SSDL</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/02/08/10175.aspx</link><pubDate>Fri, 08 Feb 2008 17:00:25 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10175</guid><dc:creator>mtaulty</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10175</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10175</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/02/08/10175.aspx#comments</comments><description>&lt;p&gt;I have a mail from &lt;a href="http://blogs.msdn.com/timmall/default.aspx"&gt;Tim&lt;/a&gt; on the EF team that I've had for a little while. I'd asked a question about mapping and he'd given me an answer saying something like "Oh, you could always do X, Y, Z" and I'd left this mail in my inbox for a while because I've been distracted and also because I didn't really understand how to do X, Y and Z but I didn't really want to say :-)&lt;/p&gt; &lt;p&gt;Today, I think I understood a bit more of it and the result is twofold. &lt;/p&gt; &lt;p&gt;The first of those folds is that I'm thinking that I'd really like to spend maybe a week in a darkened room doing nothing but Entity Framework but I doubt that I'll get the chance as (strangely) in my job I'm not really encouraged to learn technology but that's another story and not one that I'll bore you with here.&lt;/p&gt; &lt;p&gt;The second of those folds is that I really think that the Entity Framework still has a &lt;em&gt;whole lot&lt;/em&gt; of documentation and explanation that's going to be needed if people are really going to get it - there's a lot in there and it's not immediately obvious how to use it and (frankly) right now I find that sitting in an XML editor with an EDMX file, IntelliSense, the docs and a whole tonne of curiosity is proving to be far more rewarding than sitting in the designer. Don't get me wrong, the designer's fine and I'm sure it'll get better but, right now, it seems to &lt;em&gt;limit&lt;/em&gt; choices making you think that you can only do a few things when you can actually do a lot more.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;An aside...if you're putting together some kind of data-oriented conference feel free to include &lt;strong&gt;&lt;em&gt;many&lt;/em&gt;&lt;/strong&gt; sessions on Entity Framework. I feel that you need at least;&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Overview of Entity Framework and LINQ to Entities.&lt;/li&gt; &lt;li&gt;One or possibly two sessions just to explain what SSDL, CSDL and MSL can actually do for you. It needs to be deep stuff with lots of examples.&lt;/li&gt; &lt;li&gt;Session explaining EntitySQL and what additional constructs it has (I wrote about some of those once and gathered up the links &lt;a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/08/29/9691.aspx"&gt;here&lt;/a&gt;).&lt;/li&gt; &lt;li&gt;Session explaining LINQ to Entities.&lt;/li&gt; &lt;li&gt;Possibly a session explaining how to use the designer, how to use the command line tools and what the top 10 error messages mean :-)&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Sure, it's not &lt;em&gt;every&lt;/em&gt; conference that's going to be able to include all that stuff but &lt;em&gt;someone, somewhere&lt;/em&gt; needs to do it :-)&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Anyway, what I hadn't appreciated previously that Tim had alluded to in his mail was that I can have a piece of SSDL that looks like this (deliberately kept simple);&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Schema&lt;/span&gt; &lt;span class="attr"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel.Store"&lt;/span&gt;
              &lt;span class="attr"&gt;Alias&lt;/span&gt;&lt;span class="kwrd"&gt;="Self"&lt;/span&gt;
              &lt;span class="attr"&gt;ProviderManifestToken&lt;/span&gt;&lt;span class="kwrd"&gt;="09.00.3054"&lt;/span&gt;
              &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityContainer&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="dbo"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntitySet&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Customers"&lt;/span&gt; &lt;span class="attr"&gt;EntityType&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel.Store.Customers"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityContainer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Customers"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PropertyRef&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CustomerID"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CustomerID"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nchar"&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="5"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CompanyName"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="40"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContactName"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="30"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContactTitle"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="30"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Address"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="City"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="15"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Region"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="15"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="PostalCode"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="10"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Country"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="15"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Phone"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="24"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Fax"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="24"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="InsUkCustomer"&lt;/span&gt;
                  &lt;span class="attr"&gt;IsComposable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;CommandText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;insert customers(CustomerId,CompanyName) values(@Id, @Company)&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;CommandText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Parameter&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Id"&lt;/span&gt;
                     &lt;span class="attr"&gt;Mode&lt;/span&gt;&lt;span class="kwrd"&gt;="In"&lt;/span&gt;
                     &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Parameter&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Company"&lt;/span&gt;
                     &lt;span class="attr"&gt;Mode&lt;/span&gt;&lt;span class="kwrd"&gt;="In"&lt;/span&gt;
                     &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="DelUkCustomer"&lt;/span&gt;
                  &lt;span class="attr"&gt;IsComposable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;CommandText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            delete customers where customerid = @id
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;CommandText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Parameter&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Id"&lt;/span&gt;
                     &lt;span class="attr"&gt;Mode&lt;/span&gt;&lt;span class="kwrd"&gt;="In"&lt;/span&gt;
                     &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="nvarchar"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;            
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="UpdUkCustomer"&lt;/span&gt;
                  &lt;span class="attr"&gt;IsComposable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;CommandText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            /* TODO */
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;CommandText&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Function&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Schema&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;This is just saying that we have an entity in the DB called &lt;strong&gt;Customers&lt;/strong&gt; (it's from Northwind) and that we've got three functions. Except, they're not really functions. They're just pieces of SQL defined right here in the SSDL file with the &lt;strong&gt;&amp;lt;CommandText/&amp;gt;&lt;/strong&gt; element. I hadn't appreciated that this was something that I could do - I figured that Functions meant SPs in the database but, clearly, that's not the case :-)&lt;/p&gt;
&lt;p&gt;With that in place, I've defined in my conceptual model an entity set called &lt;strong&gt;UkCustomers&lt;/strong&gt; which is ( as you'd expect ) just populated with customers from the UK. It looks like this;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Schema&lt;/span&gt; &lt;span class="attr"&gt;Namespace&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel"&lt;/span&gt;
              &lt;span class="attr"&gt;Alias&lt;/span&gt;&lt;span class="kwrd"&gt;="Self"&lt;/span&gt;
              &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/ado/2006/04/edm"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityContainer&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindEntities"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntitySet&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="UkCustomers"&lt;/span&gt;
                     &lt;span class="attr"&gt;EntityType&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel.Customers"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityContainer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Customers"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PropertyRef&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CustomerID"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CustomerID"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="5"&lt;/span&gt;
                    &lt;span class="attr"&gt;FixedLength&lt;/span&gt;&lt;span class="kwrd"&gt;="true"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CompanyName"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="40"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContactName"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="30"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ContactTitle"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="30"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Address"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="60"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="City"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="15"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Region"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="15"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="PostalCode"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="10"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Country"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="15"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Phone"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="24"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Fax"&lt;/span&gt;
                    &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&lt;/span&gt;
                    &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;="24"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Schema&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, nothing radical in there at all but what I find "fun" is in the MSL mapping between these two things which I did using a &lt;strong&gt;QueryView&lt;/strong&gt;. &lt;a href="http://www.thedatafarm.com/blog/"&gt;Julie&lt;/a&gt; has a great post over &lt;a href="http://www.thedatafarm.com/blog/2007/11/02/EDMQueryViewsVsDefiningQueriesAndReadonlyViews.aspx"&gt;here&lt;/a&gt; about &lt;strong&gt;QueryViews&lt;/strong&gt; and &lt;strong&gt;DefiningQuery.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here's my mapping;&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Mapping&lt;/span&gt; &lt;span class="attr"&gt;Space&lt;/span&gt;&lt;span class="kwrd"&gt;="C-S"&lt;/span&gt;
               &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="urn:schemas-microsoft-com:windows:storage:mapping:CS"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityContainerMapping&lt;/span&gt; &lt;span class="attr"&gt;StorageEntityContainer&lt;/span&gt;&lt;span class="kwrd"&gt;="dbo"&lt;/span&gt;
                                &lt;span class="attr"&gt;CdmEntityContainer&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindEntities"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntitySetMapping&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="UkCustomers"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;QueryView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              using NorthwindModel;
              select value NorthwindModel.Customers(
              c.CustomerID, c.CompanyName, c.ContactName, c.ContactTitle,
              c.Address, c.City, c.Region, c.PostalCode, c.Country,
              c.Phone, c.Fax)
              from dbo.Customers as c
              where c.Country = 'UK'
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;QueryView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityTypeMapping&lt;/span&gt; &lt;span class="attr"&gt;TypeName&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel.Customers"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ModificationFunctionMapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;InsertFunction&lt;/span&gt; &lt;span class="attr"&gt;FunctionName&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel.Store.InsUkCustomer"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScalarProperty&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CustomerID"&lt;/span&gt; &lt;span class="attr"&gt;ParameterName&lt;/span&gt;&lt;span class="kwrd"&gt;="Id"&lt;/span&gt; &lt;span class="attr"&gt;Version&lt;/span&gt;&lt;span class="kwrd"&gt;="Current"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScalarProperty&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CompanyName"&lt;/span&gt; &lt;span class="attr"&gt;ParameterName&lt;/span&gt;&lt;span class="kwrd"&gt;="Company"&lt;/span&gt; &lt;span class="attr"&gt;Version&lt;/span&gt;&lt;span class="kwrd"&gt;="Current"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;InsertFunction&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DeleteFunction&lt;/span&gt; &lt;span class="attr"&gt;FunctionName&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel.Store.DelUkCustomer"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ScalarProperty&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="CustomerID"&lt;/span&gt; &lt;span class="attr"&gt;ParameterName&lt;/span&gt;&lt;span class="kwrd"&gt;="Id"&lt;/span&gt; &lt;span class="attr"&gt;Version&lt;/span&gt;&lt;span class="kwrd"&gt;="Original"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DeleteFunction&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UpdateFunction&lt;/span&gt; &lt;span class="attr"&gt;FunctionName&lt;/span&gt;&lt;span class="kwrd"&gt;="NorthwindModel.Store.UpdUkCustomer"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ModificationFunctionMapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityTypeMapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;              
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntitySetMapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityContainerMapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Mapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;I found this "interesting" :-) I can just define a query that brings back my UK customers and when it comes to doing the insert, update, delete on it I can just map those to the (incomplete) functions that I wrote inline at the store level.&lt;/p&gt;
&lt;p&gt;Neat. Then I can go write some LINQ code;&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;using&lt;/span&gt; (NorthwindEntities ent = &lt;span class="kwrd"&gt;new&lt;/span&gt; NorthwindEntities())
      {
        Customer c = &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer()
        {
          CustomerID = &lt;span class="str"&gt;"TESTX"&lt;/span&gt;,
          CompanyName = &lt;span class="str"&gt;"C1"&lt;/span&gt;
        };
        ent.AddToUkCustomers(c);
        ent.SaveChanges();
      }&lt;/pre&gt;
&lt;p&gt;I found this exciting enough that I'm finishing this post at 1am having been playing around with this stuff - how sad is that? :-) &lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10175" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/EntityFramework/default.aspx">EntityFramework</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/DataAccess/default.aspx">DataAccess</category></item><item><title>SQLBits - Birmingham, 1st March</title><link>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/01/30/10166.aspx</link><pubDate>Wed, 30 Jan 2008 02:06:45 GMT</pubDate><guid isPermaLink="false">c62f47b3-9054-4265-9c0c-549d811810c2:10166</guid><dc:creator>mtaulty</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/rsscomments.aspx?PostID=10166</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/commentapi.aspx?PostID=10166</wfw:comment><comments>http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/01/30/10166.aspx#comments</comments><description>&lt;p&gt;Just a quick plug :-) &lt;/p&gt; &lt;p&gt;I'm speaking at the "SQLBits" conference in Birmingham on the 1st March.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://www.sqlbits.com/information/MainAgenda.aspx"&gt;The agenda is up here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;The agenda is built by voting from prospective attendees and I found it interesting in that I submitted a few sessions that looked something like;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;"Entity Framework Tour"&lt;/p&gt; &lt;p&gt;"LINQ to SQL" Tour&lt;/p&gt; &lt;p&gt;"LINQ to Entities" Tour (this is similar to the first topic but with a very different emphasis)&lt;/p&gt; &lt;p&gt;&lt;strong&gt;"Understanding LINQ"&lt;/strong&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;and what surprised me is that the last session was the one that got picked despite it being the session that I'd say is least directly related to SQL - i.e. you can quite happily have some LINQ without bothering with a relational database.&lt;/p&gt; &lt;p&gt;So...if you can make the date and the location then sign up for SQL Bits and I look forward to seeing you at my session if it appeals to you. As an aside, if there's something that you'd like to see included in a session like "Understanding LINQ in .NET Framework V3.5 and Beyond" then feel free to ping me a mail letting me know what it is that you want to see and I'll see what I can do.&lt;/p&gt;&lt;img src="http://mtaulty.com/CommunityServer/aggbug.aspx?PostID=10166" width="1" height="1"&gt;</description><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/tags/SQLServer/default.aspx">SQLServer</category></item></channel></rss>