<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx</link><description>This is 22nd post in my ongoing series of Entity Framework Tips . If you want to do eager loading with the Entity Framework it is generally really easy, you simply write something like this: 
 var results = from post in ctx.Posts.Include(“Comments”)</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#10143794</link><pubDate>Mon, 21 Mar 2011 11:38:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10143794</guid><dc:creator>Vincent Ottens</dc:creator><description>&lt;p&gt;Hi Alex,&lt;/p&gt;
&lt;p&gt;Create post, it helped me a lot! I tried to use eagor loading wile doing a &amp;quot;group by into&amp;quot;. This didn&amp;#39;t work because of the anonymous that is created by the group by. your post directed me in the right direction.&lt;/p&gt;
&lt;p&gt;Thnx&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10143794" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#10079479</link><pubDate>Fri, 22 Oct 2010 13:33:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10079479</guid><dc:creator>Anand</dc:creator><description>&lt;p&gt;Hi Alex,&lt;/p&gt;
&lt;p&gt;I am having a similar question as Rishi and Lori. I am coming to the conclusion that it is not possible to filter children records based during eager loading and include. Is that correct?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10079479" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#10032962</link><pubDate>Wed, 30 Jun 2010 17:28:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10032962</guid><dc:creator>BJenkins</dc:creator><description>&lt;p&gt;The line that reads: &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var mem = (MemberExpression)param.Body;&lt;/p&gt;
&lt;p&gt;should, instead, be: &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var mem = (MemberExpression)exp.Body;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10032962" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#10016393</link><pubDate>Thu, 27 May 2010 16:14:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10016393</guid><dc:creator>kevin sucre</dc:creator><description>&lt;p&gt;dont wait for MS, just use expression trees:&lt;/p&gt;
&lt;p&gt;public static class ObjectQueryExtension&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static ObjectQuery&amp;lt;T&amp;gt; Include&amp;lt;T,TProperty&amp;gt;(this ObjectQuery&amp;lt;T&amp;gt; obj, Expression&amp;lt;Func&amp;lt;T,TProperty&amp;gt;&amp;gt; exp)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;where T:EntityObject&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;var mem = (MemberExpression)param.Body;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;obj.Include(mem.Member.Name);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;return obj;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10016393" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#10010901</link><pubDate>Tue, 11 May 2010 12:22:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10010901</guid><dc:creator>neothemachine</dc:creator><description>&lt;p&gt;This works with eager loading:&lt;/p&gt;
&lt;p&gt;var r =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;(from n in context.News.Include(&amp;quot;Sources&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; select n).ToList();&lt;/p&gt;
&lt;p&gt;This doesn&amp;#39;t work:&lt;/p&gt;
&lt;p&gt;var r =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;(from n in context.News.Include(&amp;quot;Sources&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; let calculation = true&lt;/p&gt;
&lt;p&gt; &amp;nbsp; select n).ToList();&lt;/p&gt;
&lt;p&gt;The let-assignment could be anything later used in the query, maybe in a where-condition. But even the simple case with a &amp;quot;true&amp;quot; assignment drops eager loading.&lt;/p&gt;
&lt;p&gt;This does work:&lt;/p&gt;
&lt;p&gt;var r =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;((from n in context.News&lt;/p&gt;
&lt;p&gt; &amp;nbsp; let calculation = true&lt;/p&gt;
&lt;p&gt; &amp;nbsp; select n) as ObjectQuery&amp;lt;Post&amp;gt;).Include(&amp;quot;Sources&amp;quot;).ToList();&lt;/p&gt;
&lt;p&gt;Why??? This seems pretty stupid to me and is a major missing &amp;quot;feature&amp;quot;.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10010901" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#9995477</link><pubDate>Tue, 13 Apr 2010 23:12:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9995477</guid><dc:creator>Lori</dc:creator><description>&lt;p&gt;Hi Alex,&lt;/p&gt;
&lt;p&gt;I have the exact same issue as Rishi (Posted Feb 2). &amp;nbsp;Being able to filter the children records on a parent would be AWESOME. &amp;nbsp;I just started using EF and RIA services and I can't figure out how to do this one - and it's driving me crazy! &lt;/p&gt;
&lt;p&gt;This was an excellent post!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9995477" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#9970192</link><pubDate>Fri, 26 Feb 2010 23:03:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9970192</guid><dc:creator>Daniel Laberge</dc:creator><description>&lt;p&gt;Thanks a lot for this post, this problem was driving me mad!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9970192" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#9956936</link><pubDate>Tue, 02 Feb 2010 14:03:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9956936</guid><dc:creator>Rishi</dc:creator><description>&lt;p&gt;Hi Alex&lt;/p&gt;
&lt;p&gt;Is there anyway so that i can apply a filter on child records and only those child records which satisfy the filter condition should be included with Parent Entity.&lt;/p&gt;
&lt;p&gt;To further Clarify.. My Problem is that i have ORDER Entity Type and ORDERDETAILS Entity Type. I want only those ORDERDETAILS included with ORDER Entity which satisfy some criteria not all the ORDERDETAILS.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9956936" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#9951850</link><pubDate>Fri, 22 Jan 2010 07:12:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9951850</guid><dc:creator>Daniel Chambers</dc:creator><description>&lt;p&gt;Just an FYI for anyone trying to do the &amp;quot;as ObjectQuery&amp;lt;Post&amp;gt;&amp;quot; in a compiled query: it won't work. &lt;/p&gt;
&lt;p&gt;However, if you do a normal cast instead of using the &amp;quot;as&amp;quot; keyword, it will work. The syntax isn't as nice, but at least it works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9951850" width="1" height="1"&gt;</description></item><item><title>re: Tip 22 - How to make Include really Include</title><link>http://blogs.msdn.com/b/alexj/archive/2009/06/02/tip-22-how-to-make-include-really-include.aspx#9938595</link><pubDate>Fri, 18 Dec 2009 09:05:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9938595</guid><dc:creator>serge.mueller.zh.ch@gmail.com</dc:creator><description>&lt;p&gt;Hello there,&lt;/p&gt;
&lt;p&gt;i've got a related question.. is there a way to retrieve the includes that were made on a ObjectQuery&amp;lt;&amp;gt; so i may reapply them when needed (at the latest possible moment) ? &lt;/p&gt;
&lt;p&gt;We use some basic functionality that predefines includes which get lost along the way..&lt;/p&gt;
&lt;p&gt;that would be very helpful... otherwise we have a huge design breaking change ahead of us..&lt;/p&gt;
&lt;p&gt;Yours serge&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9938595" width="1" height="1"&gt;</description></item></channel></rss>