<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.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>Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx</link><description>I defined an Include with Func . Cool. But what about Include(&amp;quot;Products.Order_Details&amp;quot;)? Indeed my Include can only take one relationship level. So I change my code like this: public static class ObjectQueryExtension { public static ObjectQuery</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Un pattern şi trei implementări (partea 2)</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1739867</link><pubDate>Sun, 15 Nov 2009 14:27:50 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1739867</guid><dc:creator>Tudor Turcu - blog</dc:creator><description>&lt;p&gt;După *** spuneam &amp;icirc;n postul precedent , fiecare O/RM are propria metodă de a descrie graful de obiecte&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1739867" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1738397</link><pubDate>Sun, 08 Nov 2009 15:08:40 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1738397</guid><dc:creator>Matthieu MEZIL</dc:creator><description>&lt;p&gt;Try with DirectCast instead of TryCast. It was stupid in my case to use the as operator instead a direct cast.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1738397" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1734214</link><pubDate>Thu, 22 Oct 2009 08:50:48 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1734214</guid><dc:creator>Ralf</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thanks a lot for this code.&lt;/p&gt;
&lt;p&gt;I was looking for something like that since I do not want to have strings for names sitting there too.&lt;/p&gt;
&lt;p&gt;Now, I only have a strange problem: When I build a query and .Include it passes the data to the FuncToString routine as a ExpressionType.Convert (10) and not one of the three defined to work with.&lt;/p&gt;
&lt;p&gt;I added another line to the case section, like this&lt;/p&gt;
&lt;p&gt;Case ExpressionType.Convert&lt;/p&gt;
&lt;p&gt;Return TryCast(TryCast(TryCast(selector, UnaryExpression).Operand, MemberExpression).Member, Reflection.PropertyInfo).Name (VB Syntax)&lt;/p&gt;
&lt;p&gt;which is exactly the same as the .MemberAccess case except for another TryCase selector to UnaryExpression first.&lt;/p&gt;
&lt;p&gt;I have no idea what I am doing there, how why what when, but it seems to work. Has anybody a hint why this change is needed, or what I was doing wrong in the first place? Why do I end up with ExpressionType Convert??&lt;/p&gt;
&lt;p&gt;I have a second far harder question too: If you have two entities mapped m:n and the middle table of the database does not appear in your entity model (I like that...) I cannot get the function to work at all.&lt;/p&gt;
&lt;p&gt;Any hint on that?&lt;/p&gt;
&lt;p&gt;Thanks a lot!&lt;/p&gt;
&lt;p&gt;Ralf&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1734214" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1724363</link><pubDate>Thu, 17 Sep 2009 13:05:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1724363</guid><dc:creator>Matthieu MEZIL</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;the problem with your solution is with collection : customers.Include(&amp;quot;Orders.OrderDetails&amp;quot;)&lt;/p&gt;
&lt;p&gt;That&amp;#39;s why I did it like this&lt;/p&gt;
&lt;p&gt;Matthieu&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1724363" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1724362</link><pubDate>Thu, 17 Sep 2009 12:53:59 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1724362</guid><dc:creator>Kamil</dc:creator><description>&lt;p&gt;I thinkk this is better:&lt;/p&gt;
&lt;p&gt;public static ObjectQuery&amp;lt;T,K&amp;gt; Include&amp;lt;T&amp;gt;(this ObjectQuery&amp;lt;T&amp;gt; mainQuery, Expression&amp;lt;Func&amp;lt;T, K&amp;gt;&amp;gt; subSelector)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;	var sb = new StringBuilder();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FuncToString(sb, keyExpression.Body);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return mainQuery.Include(sb.ToString());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private static void FuncToString(StringBuilder sb, Expression selector)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch (selector.NodeType)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case ExpressionType.Parameter:&lt;/p&gt;
&lt;p&gt;// &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sb.Append(((ParameterExpression) selector).Name);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case ExpressionType.MemberAccess:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FuncToString(sb, ((MemberExpression) selector).Expression);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sb.Append(&amp;quot;.&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sb.Append(((MemberExpression) selector).Member.Name);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new InvalidOperationException();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;And now you can use like this:&lt;/p&gt;
&lt;p&gt;query.Include(c=&amp;gt;c.Session)&lt;/p&gt;
&lt;p&gt;.Incude(c=&amp;gt;c.Session.User) &lt;/p&gt;
&lt;p&gt;:)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1724362" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1707135</link><pubDate>Thu, 23 Jul 2009 20:47:12 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1707135</guid><dc:creator>Matthieu MEZIL</dc:creator><description>&lt;p&gt;Thanks a lot Diego&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1707135" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1707128</link><pubDate>Thu, 23 Jul 2009 20:39:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1707128</guid><dc:creator>Diego Vega</dc:creator><description>&lt;p&gt;@Ken, I too wish we had addressed this in .NET 4.0, but unfortunately it didn’t climb to the top of the priority list as we were implementing other features (i.e. POCO support, functions exposed in LINQ, model defined functions, T4 integration, FK support, Contains, DefaultIfEmpty, Single/First/OrDefault, better stored procedure support, ExecuteStoreQuery/Translate, OrderBy Lifting, improvements for StartsWith, optimizations for non-unicode columns, EntityDataSource improvements including LINQ support, etc).&lt;/p&gt;
&lt;p&gt;It is hard to get any new feature in for .NET 4.0 at this point, but I promise I will bring it up for the next version.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1707128" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1704831</link><pubDate>Wed, 22 Jul 2009 00:33:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1704831</guid><dc:creator>Ken Smith</dc:creator><description>&lt;p&gt;Very cool! &amp;nbsp;I also hate using strings in this context: it seems counterintuitive, and very susceptible to mistakes. &amp;nbsp;At the same time, I&amp;#39;m not sure I&amp;#39;ll be using this method. &amp;nbsp;Which of the following is easier for the next guy looking at my code to understand?&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Room room = ctx.Room&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(&amp;quot;Sessions.User&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(&amp;quot;Sessions.Whiteboards.Owner&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(&amp;quot;Sessions.Whiteboards.WhiteboardShape&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(&amp;quot;Sessions.MediaStreams&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(&amp;quot;Owner&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.FirstOrDefault(r =&amp;gt; r.OwnerID == ownerUserID &amp;amp;&amp;amp; r.Name == roomName);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Room room2 = ctx.Room&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(r =&amp;gt; r.Sessions.Include&amp;lt;Session, User&amp;gt;(s =&amp;gt; s.User))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(r =&amp;gt; r.Sessions.Include&amp;lt;Session, Whiteboard&amp;gt;(s =&amp;gt; s.Whiteboards).Include&amp;lt;Whiteboard, User&amp;gt;(w =&amp;gt; w.Owner))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(r =&amp;gt; r.Sessions.Include&amp;lt;Session, Whiteboard&amp;gt;(s =&amp;gt; s.Whiteboards).Include&amp;lt;Whiteboard, WhiteboardShape&amp;gt;(w =&amp;gt; w.WhiteboardShape))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(r =&amp;gt; r.Sessions.Include&amp;lt;Session, MediaStream&amp;gt;(s =&amp;gt; s.MediaStreams))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Include(r =&amp;gt; r.Owner)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.FirstOrDefault(r =&amp;gt; r.OwnerID == ownerUserID &amp;amp;&amp;amp; r.Name == roomName);&lt;/p&gt;
&lt;p&gt;They both do the same thing, but it requires a great deal more effort to understand what the second one is doing. &amp;nbsp;I don&amp;#39;t like the first way at all -- but the second way is, if anything, uglier and more complicated.&lt;/p&gt;
&lt;p&gt;That&amp;#39;s not to say I don&amp;#39;t appreciate the code -- I very much do! &amp;nbsp;You&amp;#39;re trying to solve a problem that MS really should have solved itself. &amp;nbsp;There just doesn&amp;#39;t seem to be an easy way to solve it.&lt;/p&gt;
&lt;p&gt;Does anyone know if MS has addressed this in .NET 4.0?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1704831" width="1" height="1"&gt;</description></item><item><title>Entity Framework Include with Func</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1689650</link><pubDate>Tue, 21 Apr 2009 21:49:01 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1689650</guid><dc:creator>Jiří {x2} Činčura</dc:creator><description>&lt;p&gt;Really good extension methods. &lt;a rel="nofollow" target="_new" href="http://msmvps.com/blogs/matthieu/archive/2008/06/06/entityframework-include-with-func.aspx"&gt;msmvps.com/.../entityframework-include-with-func.aspx&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1689650" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1645888</link><pubDate>Tue, 26 Aug 2008 19:09:06 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1645888</guid><dc:creator>Matthieu MEZIL</dc:creator><description>&lt;p&gt;Thanks &lt;img src="http://msmvps.com/emoticons/emotion-2.gif" alt="Big Smile" /&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1645888" width="1" height="1"&gt;</description></item><item><title>re: Entity Framework Include with Func next</title><link>http://msmvps.com/blogs/matthieu/archive/2008/06/06/entity-framework-include-with-func-next.aspx#1645887</link><pubDate>Tue, 26 Aug 2008 19:04:12 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1645887</guid><dc:creator>Mike L</dc:creator><description>&lt;p&gt;Absolutely incredible! I don&amp;#39;t know what else to say&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1645887" width="1" height="1"&gt;</description></item></channel></rss>