<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Dan Miser - LINQ</title>
    <link>http://www.distribucon.com/blog/</link>
    <description>Thoughts from Dan Miser</description>
    <language>en-us</language>
    <copyright>Dan Miser</copyright>
    <lastBuildDate>Fri, 22 Jul 2011 00:39:06 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>dmiser@distribucon.com</managingEditor>
    <webMaster>dmiser@distribucon.com</webMaster>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=6a281769-e8de-4a5f-af31-198812806c51</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,6a281769-e8de-4a5f-af31-198812806c51.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,6a281769-e8de-4a5f-af31-198812806c51.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6a281769-e8de-4a5f-af31-198812806c51</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">The conversion is finally on. I've had
a lot of praise for <a href="http://www.mindscapehq.com/products/lightspeed">LightSpeed</a> over
the years. The guys writing it are wicked smart, and Ivan is a rockstar on the support
forums. They've solved a lot of bugs for me while I've been a customer, but the time
has come to move on.<br /><br />
I've become quite proficient with LINQ, and use it all over the place in my code.
Having to drop down and execute loops and run suboptimal queries because I have to
execute an intermediate ToList() just to get around projection and grouping errors
has taken its toll on me.<br /><br />
I truly wish the guys at Mindscape continued success, but the time has come to move
on to the company that provides a MSSQL LINQ provider that is completely fleshed out.<br /><p></p><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=6a281769-e8de-4a5f-af31-198812806c51" /></body>
      <title>Moving from LightSpeed to Entity Framework</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,6a281769-e8de-4a5f-af31-198812806c51.aspx</guid>
      <link>http://www.distribucon.com/blog/MovingFromLightSpeedToEntityFramework.aspx</link>
      <pubDate>Fri, 22 Jul 2011 00:39:06 GMT</pubDate>
      <description>The conversion is finally on. I've had a lot of praise for &lt;a href="http://www.mindscapehq.com/products/lightspeed"&gt;LightSpeed&lt;/a&gt; over
the years. The guys writing it are wicked smart, and Ivan is a rockstar on the support
forums. They've solved a lot of bugs for me while I've been a customer, but the time
has come to move on.&lt;br&gt;
&lt;br&gt;
I've become quite proficient with LINQ, and use it all over the place in my code.
Having to drop down and execute loops and run suboptimal queries because I have to
execute an intermediate ToList() just to get around projection and grouping errors
has taken its toll on me.&lt;br&gt;
&lt;br&gt;
I truly wish the guys at Mindscape continued success, but the time has come to move
on to the company that provides a MSSQL LINQ provider that is completely fleshed out.&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=6a281769-e8de-4a5f-af31-198812806c51" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,6a281769-e8de-4a5f-af31-198812806c51.aspx</comments>
      <category>.NET</category>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=af195647-2645-483d-a42e-6aed0aff1c17</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,af195647-2645-483d-a42e-6aed0aff1c17.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,af195647-2645-483d-a42e-6aed0aff1c17.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=af195647-2645-483d-a42e-6aed0aff1c17</wfw:commentRss>
      <title>LINQ to SQL: Semantics of NULL</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,af195647-2645-483d-a42e-6aed0aff1c17.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQToSQLSemanticsOfNULL.aspx</link>
      <pubDate>Fri, 15 Oct 2010 17:41:07 GMT</pubDate>
      <description>Given a method like this, with the following LINQ to SQL statement in it:
&lt;pre&gt;&lt;code&gt; public
void DisplayReport(UserStatusEnum? userStatus) ... from user in DBContext.Users where
userStatus == null ? true : userStatus.Value == user.Status select user &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
I end up with the error "Nullable object must have a value". Matt Warren (one of the
original developers on the LINQ to SQL team, and a wicked smart guy), came up with
the idea to use &lt;a href="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/d00f5611-4fce-4da4-8f79-802336fdfe1a/&gt; target="_blank"&gt;object.Equals(userStatus,
user.Status)&lt;/a&gt;, but that doesn't work for me at all in the case where userStatus
is NULL. What worked for me was to do this: &lt;pre&gt;&lt;code&gt; from user in DBContext.Users
where userStatus == null || userStatus == user.Status select user &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
The thing is, as one commenter in the linked thread mentioned, LINQ to SQL should
be a unifying syntax. We shouldn't have to distinguish between NULL and values just
because the underlying provider makes a distinction between the two. I think this
is a huge hole, but alas, one that will most likely never be plugged since LINQ to
SQL is getting deprecated. Time to check what happens in EF4...&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=af195647-2645-483d-a42e-6aed0aff1c17" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,af195647-2645-483d-a42e-6aed0aff1c17.aspx</comments>
      <category>.NET</category>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Consider this code fragment:<br /><pre class="c#" name="code">
var list =<br />
from tx in Transactions<br />
group tx by new {tx.TransactionType, tx.ClientTypeID};<br /><br />
foreach (var item in list)<br />
{<br />
Console.WriteLine(item.Key.TransactionType);<br />
Console.WriteLine(item.Sum(tx =&gt; tx.Amount));<br />
foreach (var item2 in item)<br />
Console.WriteLine(item2.TransactionID);<br />
} </pre><p />
After executing the query, we now have an IGrouping&lt;AnonymousType, Transaction&gt;
that lets us run through all of the grouped objects, while still having access to
the original objects in the inner loop. We can accomplish the exact same thing with
this alternative LINQ statement, but the first version seems cleaner to me:<br /><pre class="c#" name="code">
var list =<br />
from tx in Transactions<br />
group tx by new {tx.TransactionType, tx.ClientTypeID} into g<br />
select g; </pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9" /></body>
      <title>LINQ: Query body must end with a select OR groupby clause</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQQueryBodyMustEndWithASelectORGroupbyClause.aspx</link>
      <pubDate>Tue, 05 Jan 2010 16:30:01 GMT</pubDate>
      <description>Consider this code fragment:&lt;br /&gt;
&lt;pre class=c# name="code"&gt;
var list =&lt;br /&gt;
from tx in Transactions&lt;br /&gt;
group tx by new {tx.TransactionType, tx.ClientTypeID};&lt;br /&gt;
&lt;br /&gt;
foreach (var item in list)&lt;br /&gt;
{&lt;br /&gt;
Console.WriteLine(item.Key.TransactionType);&lt;br /&gt;
Console.WriteLine(item.Sum(tx =&amp;gt; tx.Amount));&lt;br /&gt;
foreach (var item2 in item)&lt;br /&gt;
Console.WriteLine(item2.TransactionID);&lt;br /&gt;
} &lt;/pre&gt;
&lt;p /&gt;
After executing the query, we now have an IGrouping&amp;lt;AnonymousType, Transaction&amp;gt;
that lets us run through all of the grouped objects, while still having access to
the original objects in the inner loop. We can accomplish the exact same thing with
this alternative LINQ statement, but the first version seems cleaner to me:&lt;br /&gt;
&lt;pre class=c# name="code"&gt;
var list =&lt;br /&gt;
from tx in Transactions&lt;br /&gt;
group tx by new {tx.TransactionType, tx.ClientTypeID} into g&lt;br /&gt;
select g; &lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,0572ab77-105e-4ad4-b4a0-f3f6ffcd5ed9.aspx</comments>
      <category>.NET</category>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=30b6e8a6-7d18-49a3-825c-ea4c0c2006fc</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,30b6e8a6-7d18-49a3-825c-ea4c0c2006fc.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,30b6e8a6-7d18-49a3-825c-ea4c0c2006fc.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=30b6e8a6-7d18-49a3-825c-ea4c0c2006fc</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Given a collection of players that were
constructed like this: <pre><code> private static IList&lt;Player&gt; LoadPlayers()
{ Player favre = new Player { Id = 1, Name = "Favre", Team = new Team { Id = 1, Name
= "Vikings" } }; Player peterson = new Player { Id = 2, Name = "Peterson", Team =
new Team { Id = 1, Name = "Vikings" } }; Player rodgers = new Player { Id = 3, Name
= "Rodgers", Team = new Team { Id = 2, Name = "Packers" } }; Player driver = new Player
{ Id = 4, Name = "Driver", Team = new Team { Id = 2, Name = "Packers" } }; List&lt;Player&gt;
players = new List&lt;Player&gt; {favre, peterson, rodgers, driver}; return players;
} </code></pre><p />
And the following LINQ query: <pre><code> var query = from p in LoadPlayers() group
p by p.Team into g select g; </code></pre><p />
We will see the following output: <pre><code> Vikings Vikings Packers Packers </code></pre><p />
The reason this is happening is that we created new Team objects for each and every
Player, and when LINQ tries to group, it does so based on object equality. The solution
to this is to <a href="http://www.developer.com/net/asp/print.php/989091" target="_blank">override
the Equals() and GetHashCode() methods</a> in the Team class. After doing that, the
LINQ query will be able to group the objects up properly and just display each team
name once. <a href="http://www.jetbrains.com/resharper/" target="_blank">Resharper</a> has
a nice code generation template to create solid implementations of these methods (press
Alt+Ins to bring up the code generation menu). 
<p />
The example here is obviously contrived. We could create each team object once, and
then use the same instance during the property assignment, and if we did that, things
would work just fine. However, I ran into a more generalized version of this problem
when using WCF and a lot of custom code generation. The underlying lesson is still
the same: LINQ and GroupBy need to have object equality defined properly in order
to make things work as you would expect.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=30b6e8a6-7d18-49a3-825c-ea4c0c2006fc" /></body>
      <title>LINQ GroupBy requires object equality</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,30b6e8a6-7d18-49a3-825c-ea4c0c2006fc.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQGroupByRequiresObjectEquality.aspx</link>
      <pubDate>Fri, 16 Oct 2009 18:14:18 GMT</pubDate>
      <description>Given a collection of players that were constructed like this:
&lt;pre&gt;&lt;code&gt; private
static IList&amp;lt;Player&amp;gt; LoadPlayers() { Player favre = new Player { Id = 1, Name
= "Favre", Team = new Team { Id = 1, Name = "Vikings" } }; Player peterson = new Player
{ Id = 2, Name = "Peterson", Team = new Team { Id = 1, Name = "Vikings" } }; Player
rodgers = new Player { Id = 3, Name = "Rodgers", Team = new Team { Id = 2, Name =
"Packers" } }; Player driver = new Player { Id = 4, Name = "Driver", Team = new Team
{ Id = 2, Name = "Packers" } }; List&amp;lt;Player&amp;gt; players = new List&amp;lt;Player&amp;gt;
{favre, peterson, rodgers, driver}; return players; } &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
And the following LINQ query: &lt;pre&gt;&lt;code&gt; var query = from p in LoadPlayers() group
p by p.Team into g select g; &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
We will see the following output: &lt;pre&gt;&lt;code&gt; Vikings Vikings Packers Packers &lt;/code&gt;&lt;/pre&gt;
&lt;p /&gt;
The reason this is happening is that we created new Team objects for each and every
Player, and when LINQ tries to group, it does so based on object equality. The solution
to this is to &lt;a href="http://www.developer.com/net/asp/print.php/989091" target="_blank"&gt;override
the Equals() and GetHashCode() methods&lt;/a&gt; in the Team class. After doing that, the
LINQ query will be able to group the objects up properly and just display each team
name once. &lt;a href="http://www.jetbrains.com/resharper/" target="_blank"&gt;Resharper&lt;/a&gt; has
a nice code generation template to create solid implementations of these methods (press
Alt+Ins to bring up the code generation menu). 
&lt;p /&gt;
The example here is obviously contrived. We could create each team object once, and
then use the same instance during the property assignment, and if we did that, things
would work just fine. However, I ran into a more generalized version of this problem
when using WCF and a lot of custom code generation. The underlying lesson is still
the same: LINQ and GroupBy need to have object equality defined properly in order
to make things work as you would expect.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=30b6e8a6-7d18-49a3-825c-ea4c0c2006fc" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,30b6e8a6-7d18-49a3-825c-ea4c0c2006fc.aspx</comments>
      <category>.NET</category>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=b976217f-2f8e-44f1-9e5b-a52e2e8713ce</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,b976217f-2f8e-44f1-9e5b-a52e2e8713ce.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,b976217f-2f8e-44f1-9e5b-a52e2e8713ce.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=b976217f-2f8e-44f1-9e5b-a52e2e8713ce</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
To be sure, this is an incomplete list, but it is a good start. Here's what I don't
like about LINQ to SQL:
</p>
        <ul>
          <li>
It only works with MSSQL. Yes, this point has been beaten to death, but it is entirely
justified. <a href="http://code2code.net/DB_Linq/" target="_blank">Third party solutions</a> don't
cut it. LINQ to SQL intentionally seeks to exclude a sizeable population because of
this hair-brained decision. 
</li>
          <li>
No way to easily specify adhoc LINQ queries. <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" target="_blank">This</a> doesn't
count. I know the benefits of design-time queries, but I should also be allowed to
shoot myself to get the added flexibility if I so choose. Building up expression trees
is not a viable option for every day development. 
</li>
          <li>
The constant labeling of LINQ to SQL as an OR/M. That label considerably overstates
what this technology does. One to one mapping between a table and a class is not really
OR/M. It seems like they want to force you to change your database by writing stored
procs and views to make your object model better. 
</li>
          <li>
There is no automated way to easily pick up changes to the database schema. 
</li>
          <li>
There is no easy way to preserve changes to the generated code. e.g. I change the
name of the automatically generated class from collection_details to CollectionDetails,
but I evolve the schema of the table. When I re-add the table, I need to set all of
the custom properties again. I know I shouldn't change generated code, but see the
next point. 
</li>
          <li>
Speaking of collection_details, it would be much better if the underlying class generator
had some options to clean up legacy table names (e.g. remove underscores, camel case
resulting table and column names). 
</li>
          <li>
No many-to-many support. In short, when you have an <a href="http://en.wikipedia.org/wiki/Associative_Entities" target="_blank">junction
table</a> (aka associative table or cross-reference table), you will need to write
code like this: User.UserPermissions[0].Permission vs. User.Permissions[0]. Until
we see LINQ to Entity (if ever), we do have <a href="http://blogs.msdn.com/mitsu/archive/2007/06/21/how-to-implement-a-many-to-many-relationship-using-linq-to-sql.aspx" target="_blank">this</a>,
but you can't use the new entity in a LINQ query. 
</li>
          <li>
There is no built-in solution to using LINQ across tiers. I don't want to expose my
LINQ classes (see the point above about the tight coupling between database and objects)
as I may want to change my database, and I don't want that cascading to all of the
places that use it. There is also no diffgram, so even if I did it, I would have to
write my own change tracking and resolving support. I went to an OpenSpaces meeting
on this very topic during CodeMash, and the consensus was not flattering.</li>
        </ul>
        <p>
In short, it seems like this part of LINQ was released way before it was ready. But
it does demo well...
</p>
        <p>
Feel free to add your own grievance to the comments.
</p>
        <img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=b976217f-2f8e-44f1-9e5b-a52e2e8713ce" />
      </body>
      <title>Things I Don't Like About LINQ to SQL</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,b976217f-2f8e-44f1-9e5b-a52e2e8713ce.aspx</guid>
      <link>http://www.distribucon.com/blog/ThingsIDontLikeAboutLINQToSQL.aspx</link>
      <pubDate>Fri, 11 Jan 2008 18:23:26 GMT</pubDate>
      <description>&lt;p&gt;
To be sure, this is an incomplete list, but it is a good start. Here's what I don't
like about LINQ to SQL:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
It only works with MSSQL. Yes, this point has been beaten to death, but it is entirely
justified. &lt;a href="http://code2code.net/DB_Linq/" target="_blank"&gt;Third party solutions&lt;/a&gt; don't
cut it. LINQ to SQL intentionally seeks to exclude a sizeable population because of
this hair-brained decision. 
&lt;li&gt;
No way to easily specify adhoc LINQ queries. &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" target="_blank"&gt;This&lt;/a&gt; doesn't
count. I know the benefits of design-time queries, but I should also be allowed to
shoot myself to get the added flexibility if I so choose. Building up expression trees
is not a viable option for every day development. 
&lt;li&gt;
The constant labeling of LINQ to SQL as an OR/M. That label considerably overstates
what this technology does. One to one mapping between a table and a class is not really
OR/M. It seems like they want to force you to change your database by writing stored
procs and views to make your object model better. 
&lt;li&gt;
There is no automated way to easily pick up changes to the database schema. 
&lt;li&gt;
There is no easy way to preserve changes to the generated code. e.g. I change the
name of the automatically generated class from collection_details to CollectionDetails,
but I evolve the schema of the table. When I re-add the table, I need to set all of
the custom properties again. I know I shouldn't change generated code, but see the
next point. 
&lt;li&gt;
Speaking of collection_details, it would be much better if the underlying class generator
had some options to clean up legacy table names (e.g. remove underscores, camel case
resulting table and column names). 
&lt;li&gt;
No many-to-many support. In short, when you have an &lt;a href="http://en.wikipedia.org/wiki/Associative_Entities" target="_blank"&gt;junction
table&lt;/a&gt; (aka associative table or cross-reference table), you will need to write
code like this: User.UserPermissions[0].Permission vs. User.Permissions[0]. Until
we see LINQ to Entity (if ever), we do have &lt;a href="http://blogs.msdn.com/mitsu/archive/2007/06/21/how-to-implement-a-many-to-many-relationship-using-linq-to-sql.aspx" target="_blank"&gt;this&lt;/a&gt;,
but you can't use the new entity in a LINQ query. 
&lt;li&gt;
There is no built-in solution to using LINQ across tiers. I don't want to expose my
LINQ classes (see the point above about the tight coupling between database and objects)
as I may want to change my database, and I don't want that cascading to all of the
places that use it. There is also no diffgram, so even if I did it, I would have to
write my own change tracking and resolving support. I went to an OpenSpaces meeting
on this very topic during CodeMash, and the consensus was not flattering.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
In short, it seems like this part of LINQ was released way before it was ready. But
it does demo well...
&lt;/p&gt;
&lt;p&gt;
Feel free to add your own grievance to the comments.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=b976217f-2f8e-44f1-9e5b-a52e2e8713ce" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,b976217f-2f8e-44f1-9e5b-a52e2e8713ce.aspx</comments>
      <category>.NET</category>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=ecaf0c3a-f630-4fc9-8a20-b53fac515c8f</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,ecaf0c3a-f630-4fc9-8a20-b53fac515c8f.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,ecaf0c3a-f630-4fc9-8a20-b53fac515c8f.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=ecaf0c3a-f630-4fc9-8a20-b53fac515c8f</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have been reading Dustin Campbell's series, <a href="http://diditwith.net/2007/12/29/TwelveDaysOfRefactorXmasDayTenRefactoringInXMLLiterals.aspx" target="_blank">The
12 Days of Refactor! X-mas</a>, with interest. He's a very good writer, and has broken
down a bunch of Developer Express features into easy to digest chunks of information.
</p>
        <p>
The episode I linked to above touched on the <a href="http://msdn2.microsoft.com/en-us/library/ms364068%28vs.80%29.aspx#vb9overview_topic6" target="_blank">XML
Literal</a> support that shipped with VB in Visual Studio 2008. The one sentence summary
of this technology is that it lets the VB compiler translate raw XML in the source
code into strongly-typed code using XML classes under the hood. It's a very nice idea,
and I encourage you to look at the links to learn a little more about it.
</p>
        <p>
While the VB team thought this was a good idea and added the feature, Anders and the
C# team believed that it was superfluous to add such a thing to the C# side. I haven't
really made up my mind which group I side with yet. However, Anders is benevolent
:-), so he gave us the little-documented PasteXmlAsLinq addin that will take XML on
the clipboard and paste it into a file in C# syntax building the XML up using classes
like XElement.
</p>
        <p>
In a default install of VS2008, open C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\CSharpSamples.zip
and extract the LinqSamples\PasteXmlAsLinq files. There is a Readme.html file in there
that tells you how to build, install and use the addin. 
</p>
        <p>
While this isn't the same as VB's support for XML Literals, it does make things easier
to work with. 
</p>
        <img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=ecaf0c3a-f630-4fc9-8a20-b53fac515c8f" />
      </body>
      <title>VB XML Literal support in C#</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,ecaf0c3a-f630-4fc9-8a20-b53fac515c8f.aspx</guid>
      <link>http://www.distribucon.com/blog/VBXMLLiteralSupportInC.aspx</link>
      <pubDate>Sun, 30 Dec 2007 23:02:25 GMT</pubDate>
      <description>&lt;p&gt;
I have been reading Dustin Campbell's series, &lt;a href="http://diditwith.net/2007/12/29/TwelveDaysOfRefactorXmasDayTenRefactoringInXMLLiterals.aspx" target="_blank"&gt;The
12 Days of Refactor! X-mas&lt;/a&gt;, with interest. He's a very good writer, and has broken
down a bunch of Developer Express features into easy to digest chunks of information.
&lt;/p&gt;
&lt;p&gt;
The episode I linked to above touched on the &lt;a href="http://msdn2.microsoft.com/en-us/library/ms364068%28vs.80%29.aspx#vb9overview_topic6" target="_blank"&gt;XML
Literal&lt;/a&gt; support that shipped with VB in Visual Studio 2008. The one sentence summary
of this technology is that it lets the VB compiler translate raw XML in the source
code into strongly-typed code using XML classes under the hood. It's a very nice idea,
and I encourage you to look at the links to learn a little more about it.
&lt;/p&gt;
&lt;p&gt;
While the VB team thought this was a good idea and added the feature, Anders and the
C# team believed that it was superfluous to add such a thing to the C# side. I haven't
really made up my mind which group I side with yet. However, Anders is benevolent
:-), so he gave us the little-documented PasteXmlAsLinq addin that will take XML on
the clipboard and paste it into a file in C# syntax building the XML up using classes
like XElement.
&lt;/p&gt;
&lt;p&gt;
In a default install of VS2008, open C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\CSharpSamples.zip
and extract the LinqSamples\PasteXmlAsLinq files. There is a Readme.html file in there
that tells you how to build, install and use the addin. 
&lt;/p&gt;
&lt;p&gt;
While this isn't the same as VB's support for XML Literals, it does make things easier
to work with. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=ecaf0c3a-f630-4fc9-8a20-b53fac515c8f" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,ecaf0c3a-f630-4fc9-8a20-b53fac515c8f.aspx</comments>
      <category>.NET</category>
      <category>LINQ</category>
      <category>XML</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=4c37ea38-52be-4343-bf15-2c4ba46ae3ad</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,4c37ea38-52be-4343-bf15-2c4ba46ae3ad.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,4c37ea38-52be-4343-bf15-2c4ba46ae3ad.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=4c37ea38-52be-4343-bf15-2c4ba46ae3ad</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I was banging through some quick and dirty
sample applications today, in preparation for a talk on LINQ tonight. One of my old
LINQ to SQL demos shows how to use the external xml mapping file. I also <a href="http://www.distribucon.com/blog/PermaLink,guid,974.aspx" target="_new">blogged
about this before</a>. Today, I kept getting the following error whenever I would
run with an external xml mapping file:<br /><pre><code>The type 'Order' is not an entity.</code></pre><p>
I was using the following command line to generate the xml mapping file:<br /></p><pre><code>SqlMetal /server:(local) /database:Northwind /map:Northwind.xml /code:Northwind.cs
/pluralize</code></pre><p>
Looking at the resulting xml file, I finally noticed this section:<br /></p><pre><code> &lt;Table Name="Orders"&gt; &lt;Type Name=".Order"&gt; </code></pre><p>
Notice the leading dot before the type name attribute. That's the problem. So I went
back and added the /namespace switch to the sqlMetal command line, and now all is
well with the world again. Granted, this problem is the result of me doing demo work,
and not production work, but it's still a little bit irritating. Then again, I'm still
running the May 2006 CTP on VS2005, so for all I know, MS has already fixed all of
this with a subsequent release of a build in Orcas.
</p><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=4c37ea38-52be-4343-bf15-2c4ba46ae3ad" /></body>
      <title>sqlMetal mapping file generation requires namespaces</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,4c37ea38-52be-4343-bf15-2c4ba46ae3ad.aspx</guid>
      <link>http://www.distribucon.com/blog/sqlMetalMappingFileGenerationRequiresNamespaces.aspx</link>
      <pubDate>Thu, 08 Feb 2007 19:23:16 GMT</pubDate>
      <description>I was banging through some quick and dirty sample applications today, in preparation for a talk on LINQ tonight. One of my old LINQ to SQL demos shows how to use the external xml mapping file. I also &lt;a href="http://www.distribucon.com/blog/PermaLink,guid,974.aspx" target=_new&gt;blogged
about this before&lt;/a&gt;. Today, I kept getting the following error whenever I would
run with an external xml mapping file:&lt;br&gt;
&lt;pre&gt;&lt;code&gt;The type 'Order' is not an entity.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
I was using the following command line to generate the xml mapping file:&lt;br&gt;
&lt;pre&gt;&lt;code&gt;SqlMetal /server:(local) /database:Northwind /map:Northwind.xml /code:Northwind.cs
/pluralize&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Looking at the resulting xml file, I finally noticed this section:&lt;br&gt;
&lt;pre&gt;&lt;code&gt; &amp;lt;Table Name="Orders"&amp;gt; &amp;lt;Type Name=".Order"&amp;gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Notice the leading dot before the type name attribute. That's the problem. So I went
back and added the /namespace switch to the sqlMetal command line, and now all is
well with the world again. Granted, this problem is the result of me doing demo work,
and not production work, but it's still a little bit irritating. Then again, I'm still
running the May 2006 CTP on VS2005, so for all I know, MS has already fixed all of
this with a subsequent release of a build in Orcas.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=4c37ea38-52be-4343-bf15-2c4ba46ae3ad" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,4c37ea38-52be-4343-bf15-2c4ba46ae3ad.aspx</comments>
      <category>.NET</category>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=1010</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,1010.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,1010.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1010</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">The following code snippet shows how to
pick up the SQL that will be generated by a given LINQ query. The DataContext.GetQueryText()
method makes this very easy. However, what we <b>REALLY</b> need is an easy way to
go the other way, too. For example, given an adhoc string, generate the DLINQ query
to allow further processing. I've looked through the Interactive Query sample, but
that's not exactly what I want. The 2 main things wrong with it are that the baseQuery
is already defined as an IQueryable variable, as opposed to a simple string; and the
code to build up the expression tree is much too complex for every day needs. If we
had a generic string to IQueryable method, we wouldn't need all of the expression
code. 
<p></p><pre><code> static void Main(string[] args) { string s; var q = from e in db.Employees
select e.FirstName; s = db.GetQueryText(q); Console.WriteLine(s); Console.ReadLine();
} </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1010" /></body>
      <title>LINQ: GetQueryText</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,1010.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQGetQueryText.aspx</link>
      <pubDate>Fri, 23 Jun 2006 17:08:00 GMT</pubDate>
      <description>The following code snippet shows how to pick up the SQL that will be generated by a given LINQ query. The DataContext.GetQueryText() method makes this very easy. However, what we &lt;b&gt;REALLY&lt;/b&gt; need
is an easy way to go the other way, too. For example, given an adhoc string, generate
the DLINQ query to allow further processing. I've looked through the Interactive Query
sample, but that's not exactly what I want. The 2 main things wrong with it are that
the baseQuery is already defined as an IQueryable variable, as opposed to a simple
string; and the code to build up the expression tree is much too complex for every
day needs. If we had a generic string to IQueryable method, we wouldn't need all of
the expression code. 
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; static void Main(string[] args) { string s; var q = from e in db.Employees
select e.FirstName; s = db.GetQueryText(q); Console.WriteLine(s); Console.ReadLine();
} &lt;/code&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1010" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,1010.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=981</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,981.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,981.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=981</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Using LINQ, you can use variables for evaluation
of the query. For example, the following query works just fine. It would also work
if you used something like textBox1.Text instead of the variable s. 
<p></p><pre><code> string s = "Beverages"; var results = from c in db.Categories where
c.CategoryName == s select c.CategoryName; </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=981" /></body>
      <title>Using variables in LINQ</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,981.aspx</guid>
      <link>http://www.distribucon.com/blog/UsingVariablesInLINQ.aspx</link>
      <pubDate>Fri, 26 May 2006 13:18:00 GMT</pubDate>
      <description>Using LINQ, you can use variables for evaluation of the query. For example, the following query works just fine. It would also work if you used something like textBox1.Text instead of the variable s.
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; string s = "Beverages"; var results = from c in db.Categories where c.CategoryName
== s select c.CategoryName; &lt;/code&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=981" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,981.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=974</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,974.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,974.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=974</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">In the README for the LINQ download, one
big feature that was mentioned was the ability to use an external XML mapping file
instead of attributes. This decouples the schema information from the code, which
is good as a database schema tends to change over time, and you don't want to recompile
every time your DBA decides to change something on you. The down side is that there
isn't much information out there on how to get it to work. Hopefully, this entry fills
that gap. 
<p>
The first thing to note is the syntax of the XML mapping file. You can take a look
at LINQ Preview\Docs\DLINQ Mapping Schema.xsd for more information on the mapping
format, but here is a shortened extract from LINQ Preview\Data\samplemapping.xml to
give you a look at a concrete implementation: 
</p><p></p><pre><code> &lt;?xml version="1.0" encoding="Windows-1252"?&gt; &lt;Database Name="Northwind"&gt;
&lt;Table Name="Categories"&gt; &lt;Type Name="Mapping.Category"&gt; &lt;Column Name="CategoryID"
Member="CategoryID" Storage="_CategoryID" DbType="Int NOT NULL IDENTITY" IsIdentity="True"
IsAutoGen="True" /&gt; &lt;Column Name="CategoryName" Member="CategoryName" Storage="_CategoryName"
DbType="NVarChar(15) NOT NULL" /&gt; &lt;Column Name="Description" Member="Description"
Storage="_Description" DbType="NText" UpdateCheck="Never" /&gt; &lt;Column Name="Picture"
Member="Picture" Storage="_Picture" DbType="Image" UpdateCheck="Never" /&gt; &lt;Association
Name="FK_Products_Categories" Member="Products" Storage="_Products" ThisKey="CategoryID"
OtherTable="Products" OtherKey="CategoryID" /&gt; &lt;/Type&gt; &lt;/Table&gt; &lt;/Database&gt; </code></pre><p>
The above code shows how the Categories table in the Northwind database could be mapped
in an XML file. One thing of special note here is the Association element which will
allow data hierarchies to be established, much like you can do in the DLINQ designer.
You can generate this file by hand if you want, or you can use the new version of
LINQ Preview\bin\sqlMetal.exe to generate the starting point for you. sqlMetal has
a lot of options for you to look at, including a bunch to take save snapshots of database
schema information to an xml file, and generate classes and XML mapping files from
that saved XML file. A sample command would look like this: 
</p><p></p><pre><code> sqlmetal /server:(local) /database:Northwind /map:nwindmapping.xml
/namespace:Mapping /code:nwind.cs </code></pre><p>
The resulting nwind.cs file does not contain any attributes, as they are all stored
in the xml file. To use this file, use code like this: 
</p><p></p><pre><code> XmlMappingSource mappingSource = XmlMappingSource.FromXml(File.ReadAllText("nwindmapping.xml"));
Mapping.Northwind db = new Mapping.Northwind("Integrated Security=SSPI;database=northwind;server=(local)",
mappingSource); var q = from c in db.Categories select c.CategoryName; foreach (string
s in q) listBox1.Items.Add(s); </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=974" /></body>
      <title>DLINQ XML Mapping</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,974.aspx</guid>
      <link>http://www.distribucon.com/blog/DLINQXMLMapping.aspx</link>
      <pubDate>Tue, 16 May 2006 18:10:00 GMT</pubDate>
      <description>In the README for the LINQ download, one big feature that was mentioned was the ability to use an external XML mapping file instead of attributes. This decouples the schema information from the code, which is good as a database schema tends to change over time, and you don't want to recompile every time your DBA decides to change something on you. The down side is that there isn't much information out there on how to get it to work. Hopefully, this entry fills that gap.
&lt;p&gt;
The first thing to note is the syntax of the XML mapping file. You can take a look
at LINQ Preview\Docs\DLINQ Mapping Schema.xsd for more information on the mapping
format, but here is a shortened extract from LINQ Preview\Data\samplemapping.xml to
give you a look at a concrete implementation: 
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; &amp;lt;?xml version="1.0" encoding="Windows-1252"?&amp;gt; &amp;lt;Database Name="Northwind"&amp;gt;
&amp;lt;Table Name="Categories"&amp;gt; &amp;lt;Type Name="Mapping.Category"&amp;gt; &amp;lt;Column Name="CategoryID"
Member="CategoryID" Storage="_CategoryID" DbType="Int NOT NULL IDENTITY" IsIdentity="True"
IsAutoGen="True" /&amp;gt; &amp;lt;Column Name="CategoryName" Member="CategoryName" Storage="_CategoryName"
DbType="NVarChar(15) NOT NULL" /&amp;gt; &amp;lt;Column Name="Description" Member="Description"
Storage="_Description" DbType="NText" UpdateCheck="Never" /&amp;gt; &amp;lt;Column Name="Picture"
Member="Picture" Storage="_Picture" DbType="Image" UpdateCheck="Never" /&amp;gt; &amp;lt;Association
Name="FK_Products_Categories" Member="Products" Storage="_Products" ThisKey="CategoryID"
OtherTable="Products" OtherKey="CategoryID" /&amp;gt; &amp;lt;/Type&amp;gt; &amp;lt;/Table&amp;gt; &amp;lt;/Database&amp;gt; &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The above code shows how the Categories table in the Northwind database could be mapped
in an XML file. One thing of special note here is the Association element which will
allow data hierarchies to be established, much like you can do in the DLINQ designer.
You can generate this file by hand if you want, or you can use the new version of
LINQ Preview\bin\sqlMetal.exe to generate the starting point for you. sqlMetal has
a lot of options for you to look at, including a bunch to take save snapshots of database
schema information to an xml file, and generate classes and XML mapping files from
that saved XML file. A sample command would look like this: 
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; sqlmetal /server:(local) /database:Northwind /map:nwindmapping.xml /namespace:Mapping
/code:nwind.cs &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The resulting nwind.cs file does not contain any attributes, as they are all stored
in the xml file. To use this file, use code like this: 
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; XmlMappingSource mappingSource = XmlMappingSource.FromXml(File.ReadAllText("nwindmapping.xml"));
Mapping.Northwind db = new Mapping.Northwind("Integrated Security=SSPI;database=northwind;server=(local)",
mappingSource); var q = from c in db.Categories select c.CategoryName; foreach (string
s in q) listBox1.Items.Add(s); &lt;/code&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=974" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,974.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=965</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,965.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,965.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=965</wfw:commentRss>
      <title>LINQ CTP released</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,965.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQCTPReleased.aspx</link>
      <pubDate>Thu, 11 May 2006 00:51:00 GMT</pubDate>
      <description>LINQ is coming along nicely. This release is full of goodies. Among my favorites: join support, DLINQ graphical designer, LINQ over DataSet, multi-tier enhancements, and improved conflict resolution. But the thing I'm most excited about is the addition of XML mapping of elements! I attended a &lt;a href="http://www.adapdev.com/blogs/smccormack/PermaLink,guid,7c27df4c-7887-42c4-bcfe-c4fc01af3c62.aspx" target="_new"&gt;talk
on ORM by Sean McCormack&lt;/a&gt; at the WI .NET User Group last night. He is an excellent
speaker and spoke about DLINQ for a couple minutes, but hated the fact that it didn't
have XML mapping. Maybe this will bring him around. :-) It also looks like I'll be
speaking at the WI .NET User Group on LINQ in the medium-term future. I'll be sure
to post more about that event and more findings with LINQ. In the meantime, &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&amp;displaylang=en" target="_new"&gt;download
the CTP&lt;/a&gt; now.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=965" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,965.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=804</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,804.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,804.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=804</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">A version of LINQ that is compatible with
the RTM version of VS2005 has been released on <a href="http://msdn.microsoft.com/netframework/future/linq/" target="_new">this
page</a>.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=804" /></body>
      <title>LINQ update: RTM version available</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,804.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQUpdateRTMVersionAvailable.aspx</link>
      <pubDate>Sat, 29 Oct 2005 15:00:00 GMT</pubDate>
      <description>A version of LINQ that is compatible with the RTM version of VS2005 has been released on &lt;a href="http://msdn.microsoft.com/netframework/future/linq/" target="_new"&gt;this
page&lt;/a&gt;.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=804" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,804.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=772</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,772.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,772.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=772</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">As I mentioned in my <a href="http://distribucon.com/blog/archive/2005/09/23/771.aspx" target="_new">previous
post about LINQ and IDENTITY fields</a>, I was getting an exception when trying to
update back to the DB. I have since tracked this down to my guess in that post where
it was due to the way that I constructed the customer object via foreach. Using that
technique, it seems that it keeps a DataReader open longer than needed, which results
in this error. I have a workaround, so I can at least share this sample to show you
how related tables with IDENTITY fields work. If you want to see the exception, replace
the line where I assign the cust variable with a "foreach (var cust in query)". 
<p>
Things to note in this sample:<br /></p><ul><li>
I am mixing and matching objects retrieved from the DB (cust) and locally created
objects (o and od). 
</li><li>
You can assign the Order object to the customer either by setting o.Customer to point
to the customer, or using cust.Orders.Add(o). The same holds true for adding OrderDetail
to Order. 
</li><li>
IDENTITY fields are not initialized upon creation, but they are assigned the actual
value that they got when getting inserted to the DB. 
</li><li>
You can link tables together by either using the object references or the actual data
field. For example, when building the OrderDetail object, I use od.ProductID to set
the value that will get written to the DB. I could also have constructed/received
a Product object from the DB and assigned od.Product to do the linking via object
reference. 
</li><li>
Linking between related tables is taken care of automatically, even when linked via
IDENTITY fields 
</li></ul><p></p><pre><code> class Program { static void Main(string[] args) { Northwind db = new
Northwind( @"Data Source=(local);Initial Catalog=Northwind;Integrated Security=True");
db.Log = Console.Out; var query = from c in db.Customers where c.CustomerID == "ALFKI"
select c; Customer cust = query.ToArray()[0]; Order o = new Order(); o.Customer =
cust; o.Freight = 23; Console.WriteLine("[PRE] Order.OrderID == " + o.OrderID); OrderDetail
od = new OrderDetail(); od.Order = o; od.Quantity = 1; od.ProductID = 1; Console.WriteLine("[PRE]
OrderDetail.OrderID == " + od.OrderID); //o.OrderDetails.Add(od); //cust.Orders.Add(o);
db.SubmitChanges(); Console.WriteLine("[POST] Order.OrderID == " + o.OrderID); Console.WriteLine("[POST]
OrderDetail.OrderID == " + od.OrderID); } } </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=772" /></body>
      <title>LINQ and IDENTITY, Part II</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,772.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQAndIDENTITYPartII.aspx</link>
      <pubDate>Fri, 23 Sep 2005 18:54:00 GMT</pubDate>
      <description>As I mentioned in my &lt;a href="http://distribucon.com/blog/archive/2005/09/23/771.aspx" target="_new"&gt;previous
post about LINQ and IDENTITY fields&lt;/a&gt;, I was getting an exception when trying to
update back to the DB. I have since tracked this down to my guess in that post where
it was due to the way that I constructed the customer object via foreach. Using that
technique, it seems that it keeps a DataReader open longer than needed, which results
in this error. I have a workaround, so I can at least share this sample to show you
how related tables with IDENTITY fields work. If you want to see the exception, replace
the line where I assign the cust variable with a "foreach (var cust in query)". 
&lt;p&gt;
Things to note in this sample:&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
I am mixing and matching objects retrieved from the DB (cust) and locally created
objects (o and od). 
&lt;li&gt;
You can assign the Order object to the customer either by setting o.Customer to point
to the customer, or using cust.Orders.Add(o). The same holds true for adding OrderDetail
to Order. 
&lt;li&gt;
IDENTITY fields are not initialized upon creation, but they are assigned the actual
value that they got when getting inserted to the DB. 
&lt;li&gt;
You can link tables together by either using the object references or the actual data
field. For example, when building the OrderDetail object, I use od.ProductID to set
the value that will get written to the DB. I could also have constructed/received
a Product object from the DB and assigned od.Product to do the linking via object
reference. 
&lt;li&gt;
Linking between related tables is taken care of automatically, even when linked via
IDENTITY fields 
&lt;/ul&gt;
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; class Program { static void Main(string[] args) { Northwind db = new Northwind(
@"Data Source=(local);Initial Catalog=Northwind;Integrated Security=True"); db.Log
= Console.Out; var query = from c in db.Customers where c.CustomerID == "ALFKI" select
c; Customer cust = query.ToArray()[0]; Order o = new Order(); o.Customer = cust; o.Freight
= 23; Console.WriteLine("[PRE] Order.OrderID == " + o.OrderID); OrderDetail od = new
OrderDetail(); od.Order = o; od.Quantity = 1; od.ProductID = 1; Console.WriteLine("[PRE]
OrderDetail.OrderID == " + od.OrderID); //o.OrderDetails.Add(od); //cust.Orders.Add(o);
db.SubmitChanges(); Console.WriteLine("[POST] Order.OrderID == " + o.OrderID); Console.WriteLine("[POST]
OrderDetail.OrderID == " + od.OrderID); } } &lt;/code&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=772" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,772.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=763</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,763.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,763.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=763</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">In the current version of DLINQ, you can
only target MSSQL. The architecure seems to be extensible enough to allow for DBMS
vendors to provide their own DLINQ assemblies so that when you write DLINQ queries,
you will be allowed to communicate to a variety of back-ends. See System.Data.DLinq.Provider.ProviderContext
for the class that you can use to descend from in order to get your own DBMS supported.
Talking with MS, it appears that they are hoping that each and every vendor will provide
their own assemblies. I think this is a mistake for the following reasons: 
<p></p><ul><li>
First off, the current code in System.Data.DLinq.DataContext uses code in System.Data.DLinq.SqlClient.
It essentially forces the ProviderContext to be SqlClient. This will have to be cleaned
up and made more generic before a vendor can deliver something. 
</li><li>
I believe it's time for MS to start providing tools that allow the developer to mix
and match parts. Until MS does this, they will continue to develop solutions that
work well with MSSQL, but will miss out on what other DBMSes can do. They need to
take the lead by providing other DBMS versions so they can see where the holes in
their current approach are. If they wait for the vendors, it will most likely be too
late to change the code to do what needs to be done to support 3rd party DBs. It's
a Catch-22. DB vendors will wait to write their assemblies until MS cleans up the
code (see point 1 above), and see that doing this will yield positive returns. When
they finally do this, it may be too late to have the DLINQ architecture changed to
accomodate whatever specific hooks may be required to get first-class support of the
3rd party DB. 
</li><li>
It doesn't appear that there is any registration/management code in place to allow
for you to simply say: "I'd like to use MSSQL (or Oracle, or InterBase)". It seems
that this would be resolved by which assemblies you reference in your code. But how
well will this work when you want to target multiple DBs in your application? 
</li><li>
Finally, the competition (i.e. Borland) already provides low-level multi-DB code in
several cases, and has for years: BDE, DBExpress, and Borland Data Providers (BDP).
If a company with a development team that is a minute fraction of MS's development
team can deliver this, there's no reason MS couldn't do the same. 
</li></ul><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=763" /></body>
      <title>DLINQ and MSSQL</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,763.aspx</guid>
      <link>http://www.distribucon.com/blog/DLINQAndMSSQL.aspx</link>
      <pubDate>Mon, 19 Sep 2005 03:14:00 GMT</pubDate>
      <description>In the current version of DLINQ, you can only target MSSQL. The architecure seems to be extensible enough to allow for DBMS vendors to provide their own DLINQ assemblies so that when you write DLINQ queries, you will be allowed to communicate to a variety of back-ends. See System.Data.DLinq.Provider.ProviderContext for the class that you can use to descend from in order to get your own DBMS supported. Talking with MS, it appears that they are hoping that each and every vendor will provide their own assemblies. I think this is a mistake for the following reasons:
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
First off, the current code in System.Data.DLinq.DataContext uses code in System.Data.DLinq.SqlClient.
It essentially forces the ProviderContext to be SqlClient. This will have to be cleaned
up and made more generic before a vendor can deliver something. 
&lt;li&gt;
I believe it's time for MS to start providing tools that allow the developer to mix
and match parts. Until MS does this, they will continue to develop solutions that
work well with MSSQL, but will miss out on what other DBMSes can do. They need to
take the lead by providing other DBMS versions so they can see where the holes in
their current approach are. If they wait for the vendors, it will most likely be too
late to change the code to do what needs to be done to support 3rd party DBs. It's
a Catch-22. DB vendors will wait to write their assemblies until MS cleans up the
code (see point 1 above), and see that doing this will yield positive returns. When
they finally do this, it may be too late to have the DLINQ architecture changed to
accomodate whatever specific hooks may be required to get first-class support of the
3rd party DB. 
&lt;li&gt;
It doesn't appear that there is any registration/management code in place to allow
for you to simply say: "I'd like to use MSSQL (or Oracle, or InterBase)". It seems
that this would be resolved by which assemblies you reference in your code. But how
well will this work when you want to target multiple DBs in your application? 
&lt;li&gt;
Finally, the competition (i.e. Borland) already provides low-level multi-DB code in
several cases, and has for years: BDE, DBExpress, and Borland Data Providers (BDP).
If a company with a development team that is a minute fraction of MS's development
team can deliver this, there's no reason MS couldn't do the same. 
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=763" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,763.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=761</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,761.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,761.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=761</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">There is some conflicting information out
there about what you need to run LINQ. <a href="http://msdn.microsoft.com/netframework/future/linq/" target="_new">This
link</a> says that the C# LINQ Tech Preview will only work with VS.NET 2005 Release
Candidate (RC). What is troubling is when you download the MSI file from that page,
it is the same exact MSI file as the one distributed on Disc 4 at PDC. That file would
only install on VS.NET 2005 Beta 2. 
<p>
To make matters worse, <a href="http://blogs.msdn.com/vbteam/archive/2005/09/15/467975.aspx" target="_new">this
link</a> tells us that the VB LINQ Tech Preview from the web site will only work with
VS.NET 2005 RC (as does The LINQ Project Page). If you install RC and then the VB
LINQ Tech Preview, you'll find that the files that get installed are newer than the
C# version. However, the VB package is missing the System.Data.DLinq assembly. 
</p><p>
I imagine updates will be coming to sort all of this out soon, but just thought you
should be aware of the current state of things. To make things simple for now, use
Beta 2 and C#. 
</p><p>
Edited on 9/17 to add: Looks like MS updated the page to say that C# only works with
Beta 2.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=761" /></p></body>
      <title>LINQ will only work with Beta 2</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,761.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQWillOnlyWorkWithBeta2.aspx</link>
      <pubDate>Sat, 17 Sep 2005 04:13:00 GMT</pubDate>
      <description>There is some conflicting information out there about what you need to run LINQ. &lt;a href="http://msdn.microsoft.com/netframework/future/linq/" target="_new"&gt;This
link&lt;/a&gt; says that the C# LINQ Tech Preview will only work with VS.NET 2005 Release
Candidate (RC). What is troubling is when you download the MSI file from that page,
it is the same exact MSI file as the one distributed on Disc 4 at PDC. That file would
only install on VS.NET 2005 Beta 2. 
&lt;p&gt;
To make matters worse, &lt;a href="http://blogs.msdn.com/vbteam/archive/2005/09/15/467975.aspx" target="_new"&gt;this
link&lt;/a&gt; tells us that the VB LINQ Tech Preview from the web site will only work with
VS.NET 2005 RC (as does The LINQ Project Page). If you install RC and then the VB
LINQ Tech Preview, you'll find that the files that get installed are newer than the
C# version. However, the VB package is missing the System.Data.DLinq assembly. 
&lt;p&gt;
I imagine updates will be coming to sort all of this out soon, but just thought you
should be aware of the current state of things. To make things simple for now, use
Beta 2 and C#. 
&lt;p&gt;
Edited on 9/17 to add: Looks like MS updated the page to say that C# only works with
Beta 2.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=761" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,761.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=760</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,760.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,760.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=760</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <a href="http://msdn.microsoft.com/netframework/future/linq/" target="_new">.NET
Language Integrated Query (LINQ)</a> is here. We've seen a couple of teasers over
the past few months, but after seeing this stuff in-depth for a few days, I have to
admit that I love what I see. So much so, that I <a href="http://distribucon.com/blog/category/9.aspx/rss" target="_new">created
a new feed</a> for it because I plan on writing about LINQ quite a bit. For now, the
generic description will have to do. It's a way to write query-like statements that
can operate on sets, XML, data, and more using one syntax. Furthermore, this is all
available in your native programming language (C#, VB, and others will follow soon,
I'm sure), which means rich type information at design-time, and it's strongly-typed
so you'll see errors at compile time. It's in beta right now, and there are all sorts
of known warts, but the promise of a useful and valuable tool is excellent. 
<p>
Stay tuned for more information on LINQ!<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=760" /></p></body>
      <title>LINQ is here</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,760.aspx</guid>
      <link>http://www.distribucon.com/blog/LINQIsHere.aspx</link>
      <pubDate>Sat, 17 Sep 2005 01:05:00 GMT</pubDate>
      <description>&lt;a href="http://msdn.microsoft.com/netframework/future/linq/" target="_new"&gt;.NET Language
Integrated Query (LINQ)&lt;/a&gt; is here. We've seen a couple of teasers over the past
few months, but after seeing this stuff in-depth for a few days, I have to admit that
I love what I see. So much so, that I &lt;a href="http://distribucon.com/blog/category/9.aspx/rss" target="_new"&gt;created
a new feed&lt;/a&gt; for it because I plan on writing about LINQ quite a bit. For now, the
generic description will have to do. It's a way to write query-like statements that
can operate on sets, XML, data, and more using one syntax. Furthermore, this is all
available in your native programming language (C#, VB, and others will follow soon,
I'm sure), which means rich type information at design-time, and it's strongly-typed
so you'll see errors at compile time. It's in beta right now, and there are all sorts
of known warts, but the promise of a useful and valuable tool is excellent. 
&lt;p&gt;
Stay tuned for more information on LINQ!&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=760" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,760.aspx</comments>
      <category>LINQ</category>
    </item>
  </channel>
</rss>