<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: join in LINQ to SQL and LINQ to Entities Considered Messy, Redundant</title>
	<atom:link href="http://blogs.teamb.com/craigstuntz/2010/01/13/38525/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/</link>
	<description>C# • Entity Framework • Functional Programming • MVC • Web</description>
	<pubDate>Sun, 12 Feb 2012 04:45:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Ray Akkanson</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-37742</link>
		<dc:creator>Ray Akkanson</dc:creator>
		<pubDate>Fri, 09 Dec 2011 01:38:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-37742</guid>
		<description>Great Article

Thanks
Ray Akkanson</description>
		<content:encoded><![CDATA[<p>Great Article</p>
<p>Thanks<br />
Ray Akkanson</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Stuntz</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-37029</link>
		<dc:creator>Craig Stuntz</dc:creator>
		<pubDate>Sat, 26 Nov 2011 03:37:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-37029</guid>
		<description>Leon, no, that's not valid. When comparing entities, you have to compare the ID, not the enity itself. So you can do &lt;code&gt;foo.Id = bar.Id&lt;/code&gt;, but &lt;code&gt;foo = bar&lt;/code&gt; won't work.</description>
		<content:encoded><![CDATA[<p>Leon, no, that&#8217;s not valid. When comparing entities, you have to compare the ID, not the enity itself. So you can do <code>foo.Id = bar.Id</code>, but <code>foo = bar</code> won&#8217;t work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leon Anderson</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-36999</link>
		<dc:creator>Leon Anderson</dc:creator>
		<pubDate>Fri, 25 Nov 2011 16:26:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-36999</guid>
		<description>Hi Craig,
Thanks for such a great article...
I notice though that you have no place where you join a query to another by way of entity itself, this is what I am having issue with and can not find anywhere validation for...binding inside the join on an entity return type instead of table equivalent type...

Is this valid???
ObjectQuery c2a = db.ADMINISTRATION;
IQueryable AGREEMENT_IDS =
from com2a in c2a
where com2a.DESC.Contains(keyword)
from com2b in com2a.PACK
from com2c in com2b.AGREEMENT_PACK
join com2d in db.AGREEMENT on com2c.AGREEMENT equals com2d &#60;------------- valid??
select com2d.AGREEMENT_ID;</description>
		<content:encoded><![CDATA[<p>Hi Craig,<br />
Thanks for such a great article&#8230;<br />
I notice though that you have no place where you join a query to another by way of entity itself, this is what I am having issue with and can not find anywhere validation for&#8230;binding inside the join on an entity return type instead of table equivalent type&#8230;</p>
<p>Is this valid???<br />
ObjectQuery c2a = db.ADMINISTRATION;<br />
IQueryable AGREEMENT_IDS =<br />
from com2a in c2a<br />
where com2a.DESC.Contains(keyword)<br />
from com2b in com2a.PACK<br />
from com2c in com2b.AGREEMENT_PACK<br />
join com2d in db.AGREEMENT on com2c.AGREEMENT equals com2d &lt;&#8212;&#8212;&#8212;&#8212;- valid??<br />
select com2d.AGREEMENT_ID;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mariusz Zaleski</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-21850</link>
		<dc:creator>Mariusz Zaleski</dc:creator>
		<pubDate>Mon, 03 Jan 2011 20:00:22 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-21850</guid>
		<description>Hi Craig,

thank you for an effort you've put into this post.
I have read all and it refreshed waht already know.
Refreshing is good because it lets you remember the "thing" for longer.

Your effort is appreciated :-)

Regards
Mariusz</description>
		<content:encoded><![CDATA[<p>Hi Craig,</p>
<p>thank you for an effort you&#8217;ve put into this post.<br />
I have read all and it refreshed waht already know.<br />
Refreshing is good because it lets you remember the "thing" for longer.</p>
<p>Your effort is appreciated <img src='http://blogs.teamb.com/craigstuntz/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Regards<br />
Mariusz</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Meysam</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-20969</link>
		<dc:creator>Meysam</dc:creator>
		<pubDate>Tue, 07 Dec 2010 18:34:04 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-20969</guid>
		<description>my DB has lots of relationship and as you know L2S/L2EF creates a list of.......
i use L2EF in my Silverlight application via WCF and as you know, WCF serialize result of query base on its binding. now when i send a little query(number of result) it takes much time because each object contains many data on its relationship properties.

i try select cluase clause in LINQ query but in L2S/L2EF not supported!! and also i don't want create DTO object(My DB has more than 200 table)
what's your opinion?</description>
		<content:encoded><![CDATA[<p>my DB has lots of relationship and as you know L2S/L2EF creates a list of&#8230;&#8230;.<br />
i use L2EF in my Silverlight application via WCF and as you know, WCF serialize result of query base on its binding. now when i send a little query(number of result) it takes much time because each object contains many data on its relationship properties.</p>
<p>i try select cluase clause in LINQ query but in L2S/L2EF not supported!! and also i don&#8217;t want create DTO object(My DB has more than 200 table)<br />
what&#8217;s your opinion?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rakesh</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-16733</link>
		<dc:creator>rakesh</dc:creator>
		<pubDate>Fri, 04 Jun 2010 04:26:54 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-16733</guid>
		<description>Craig,

I am trying to write a "testable code" as part of my learning process. Would look forward if you could write a post on writing testable code using C#.
Thanks</description>
		<content:encoded><![CDATA[<p>Craig,</p>
<p>I am trying to write a "testable code" as part of my learning process. Would look forward if you could write a post on writing testable code using C#.<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AL</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-14793</link>
		<dc:creator>AL</dc:creator>
		<pubDate>Thu, 04 Mar 2010 11:12:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-14793</guid>
		<description>Thank you for your informative response.
I asked you for a query to left join Customers and Orders and you gave it.

Simply adding DefaultIfEmpty() to the inner join syntax does the trick, although you spent so much time deprecating it in the original article.

&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Response:&lt;/strong&gt; My goal is to get LINQ users to think in terms of object graphs rather than relational sets. It's a critical difference which many miss because LINQ looks so much like SQL. But if &lt;/em&gt;your&lt;em&gt; goal is to throw the results into a visual control designed for a relational set, then there's nothing particularly wrong with it.&lt;/em&gt;&lt;/blockquote&gt;

I find it quite reasonable to want a result set that looks like 

select t1.ContactName, t2.Freight from Customers t1
left join Orders t2 on t1.CustomerID = t2.CustomerID</description>
		<content:encoded><![CDATA[<p>Thank you for your informative response.<br />
I asked you for a query to left join Customers and Orders and you gave it.</p>
<p>Simply adding DefaultIfEmpty() to the inner join syntax does the trick, although you spent so much time deprecating it in the original article.</p>
<blockquote><p><em><strong>Response:</strong> My goal is to get LINQ users to think in terms of object graphs rather than relational sets. It&#8217;s a critical difference which many miss because LINQ looks so much like SQL. But if </em>your<em> goal is to throw the results into a visual control designed for a relational set, then there&#8217;s nothing particularly wrong with it.</em></p></blockquote>
<p>I find it quite reasonable to want a result set that looks like </p>
<p>select t1.ContactName, t2.Freight from Customers t1<br />
left join Orders t2 on t1.CustomerID = t2.CustomerID</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AL</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-14724</link>
		<dc:creator>AL</dc:creator>
		<pubDate>Tue, 02 Mar 2010 23:15:33 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-14724</guid>
		<description>Aren't we cheating somewhat here ?

&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Response:&lt;/strong&gt; I don't think so, but then again, my goal is not to "immediately chuck the result set into a DataGridView." Yours might be, which is fine, but that just means your needs are different than mine. As for how to meet your needs, read on...&lt;/em&gt;&lt;/blockquote&gt;

In the self referencing Table Employees the field ReportsTo is nullable and actually contains nulls.
It is unusual for a foreign key to be nullable between 2 SEPARATE tables.
Try left joining Customers and Orders.
Although CustomerID in Orders is nullable, there are no Orders without a CustomerID.

&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Response:&lt;/strong&gt; Not in the data delivered with Northwind, no, but it's certainly possible.&lt;/em&gt;&lt;/blockquote&gt;

If Orders is the left table, an inner join and an outer join produce the same result anyway, and yield only those customers who have placed orders.
If Customer is the left table, the fields of Customer.Order are inaccesible.

&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Response:&lt;/strong&gt; That is wrong, on several counts. First, the property is &lt;code&gt;Order&lt;b&gt;s&lt;/b&gt;&lt;/code&gt;, not &lt;code&gt;Order&lt;/code&gt;. It's 1..*, not 1..1. Second, you certainly can use the properties of &lt;code&gt;Orders&lt;/code&gt; in a query. The following query works fine, for example:&lt;/em&gt;
&lt;code&gt;            var q = from c in context.Customers
                    from o in c.Orders
                    select new
                    {
                        Name = c.ContactName,
                        Freight = o.Freight
                    };&lt;/code&gt;&lt;/blockquote&gt;

It requires a nested foreach to convert the result set to a List. 

&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Response:&lt;/strong&gt;No. What I &lt;/em&gt;think&lt;em&gt; you're trying to say is "I don't know how to convert the result to a "flattened, SQL-like" tabular result set instead of an "object-like," hierarchical tree of customers and orders without a nested foreach (or a &lt;code&gt;join&lt;/code&gt;). But it's quite possible. I've already shown the "inner join" version above. Here's the "left join" version: &lt;/em&gt;
&lt;code&gt;            var q = from c in context.Customers
                    from o in c.Orders.DefaultIfEmpty()
                    select new
                    {
                        Name = c.ContactName,
                        Freight = o.Freight
                    };&lt;/code&gt;&lt;/blockquote&gt;

I wouldn't describe this as an improvement over 'join' where I can immediately chuck the result set into a DataGridView.

&lt;blockquote&gt;&lt;em&gt;&lt;strong&gt;Response:&lt;/strong&gt;See the query above. This isn't how I'd do it, because most use cases of such tabular result forms tend to want to group them back into hierarchies anyway (think of every reporting tool ever created). But it's certainly possible. And again, the &lt;code&gt;join&lt;/code&gt; is just noise. The association properties make it redundant and messy.&lt;/em&gt;&lt;/blockquote&gt;

Maybe you have an elegant solution to left joining Customers with Orders, i.e showing ALL Customers with or without Order details ?</description>
		<content:encoded><![CDATA[<p>Aren&#8217;t we cheating somewhat here ?</p>
<blockquote><p><em><strong>Response:</strong> I don&#8217;t think so, but then again, my goal is not to "immediately chuck the result set into a DataGridView." Yours might be, which is fine, but that just means your needs are different than mine. As for how to meet your needs, read on&#8230;</em></p></blockquote>
<p>In the self referencing Table Employees the field ReportsTo is nullable and actually contains nulls.<br />
It is unusual for a foreign key to be nullable between 2 SEPARATE tables.<br />
Try left joining Customers and Orders.<br />
Although CustomerID in Orders is nullable, there are no Orders without a CustomerID.</p>
<blockquote><p><em><strong>Response:</strong> Not in the data delivered with Northwind, no, but it&#8217;s certainly possible.</em></p></blockquote>
<p>If Orders is the left table, an inner join and an outer join produce the same result anyway, and yield only those customers who have placed orders.<br />
If Customer is the left table, the fields of Customer.Order are inaccesible.</p>
<blockquote><p><em><strong>Response:</strong> That is wrong, on several counts. First, the property is <code>Order<b>s</b></code>, not <code>Order</code>. It&#8217;s 1..*, not 1..1. Second, you certainly can use the properties of <code>Orders</code> in a query. The following query works fine, for example:</em><br />
<code>            var q = from c in context.Customers<br />
                    from o in c.Orders<br />
                    select new<br />
                    {<br />
                        Name = c.ContactName,<br />
                        Freight = o.Freight<br />
                    };</code></p></blockquote>
<p>It requires a nested foreach to convert the result set to a List. </p>
<blockquote><p><em><strong>Response:</strong>No. What I </em>think<em> you&#8217;re trying to say is "I don&#8217;t know how to convert the result to a "flattened, SQL-like" tabular result set instead of an "object-like," hierarchical tree of customers and orders without a nested foreach (or a <code>join</code>). But it&#8217;s quite possible. I&#8217;ve already shown the "inner join" version above. Here&#8217;s the "left join" version: </em><br />
<code>            var q = from c in context.Customers<br />
                    from o in c.Orders.DefaultIfEmpty()<br />
                    select new<br />
                    {<br />
                        Name = c.ContactName,<br />
                        Freight = o.Freight<br />
                    };</code></p></blockquote>
<p>I wouldn&#8217;t describe this as an improvement over &#8216;join&#8217; where I can immediately chuck the result set into a DataGridView.</p>
<blockquote><p><em><strong>Response:</strong>See the query above. This isn&#8217;t how I&#8217;d do it, because most use cases of such tabular result forms tend to want to group them back into hierarchies anyway (think of every reporting tool ever created). But it&#8217;s certainly possible. And again, the <code>join</code> is just noise. The association properties make it redundant and messy.</em></p></blockquote>
<p>Maybe you have an elegant solution to left joining Customers with Orders, i.e showing ALL Customers with or without Order details ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-13674</link>
		<dc:creator>chris</dc:creator>
		<pubDate>Fri, 29 Jan 2010 15:58:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-13674</guid>
		<description>Craig - 

I think a lot of people have missed the significance of:

from s in context.Employees
  from e in s.Employees 

as a way of doing joins.  Once you understand what you're looking at, it's obvious and makes perfect sense.   It might make sense to highlight this in a future post.  And again, thanks for the SO help.</description>
		<content:encoded><![CDATA[<p>Craig - </p>
<p>I think a lot of people have missed the significance of:</p>
<p>from s in context.Employees<br />
  from e in s.Employees </p>
<p>as a way of doing joins.  Once you understand what you&#8217;re looking at, it&#8217;s obvious and makes perfect sense.   It might make sense to highlight this in a future post.  And again, thanks for the SO help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J.W.</title>
		<link>http://blogs.teamb.com/craigstuntz/2010/01/13/38525/#comment-13414</link>
		<dc:creator>J.W.</dc:creator>
		<pubDate>Sun, 17 Jan 2010 15:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/?p=38525#comment-13414</guid>
		<description>Another good post, your answers on SO about EF is always good resource to learn EF.</description>
		<content:encoded><![CDATA[<p>Another good post, your answers on SO about EF is always good resource to learn EF.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

