<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" 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:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Coffeehouse - Need help to build Expression Tree</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Coffeehouse - Need help to build Expression Tree</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Fri, 24 May 2013 10:42:45 GMT</pubDate>
	<lastBuildDate>Fri, 24 May 2013 10:42:45 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>13</c9:totalResults>
	<c9:pageCount>-13</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>Hi Experts,</p><p>My Name is Somnath .I am working ASP.net Project in which I am using Linq</p><p>I am creating Dynamic Lamabada Expression using Expression tree</p><p>I want to use DateTime.Parse method for both the side for Property as well as Constant.</p><p>I tried following way but I am getting an error.</p><p>MethodInfo methodDateTimeParse = typeof(DateTime).GetMethod(&quot;Parse&quot;, new Type[] { typeof(string) });</p><p><strong>Expression ExprLeft = Expression.Call(Expression.Property(variable, oFC.Field), methodDateTimeParse); &nbsp;</strong><em>//Getiing error at this line (</em></p><p><em></em>Static method requires null instance, non-static method requires non-null instance.</p><p>Parameter name: instance</p><p><em>)</em></p><p>Please provide help</p><p>&nbsp;</p><p>Thanks &amp; Regards,</p><p>Somnath&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/7f6811c63c7942c4910da03e00acba8e#7f6811c63c7942c4910da03e00acba8e</link>
		<pubDate>Wed, 25 Apr 2012 10:28:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/7f6811c63c7942c4910da03e00acba8e#7f6811c63c7942c4910da03e00acba8e</guid>
		<dc:creator>Somnath Sonawne</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/somnath2107/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>It looks like Expression.Property(...) is returning null. Are `variable` and `oFC.Field` correct?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/ec81a9c3c6f94667a227a03e00c38074#ec81a9c3c6f94667a227a03e00c38074</link>
		<pubDate>Wed, 25 Apr 2012 11:51:48 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/ec81a9c3c6f94667a227a03e00c38074#ec81a9c3c6f94667a227a03e00c38074</guid>
		<dc:creator>myefforts2</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/myefforts2/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>Expression.Call(Expression.Property(...) ...) is the problem - that overload expects an instance of a class that you can call DateTime.Parse on - so it expects a DateTime object ... but Parse is static.&nbsp; So you are supposed to give it a null instance - that means use the Expression.Call overload that does not take an Expression representing the instance.&nbsp; Try this (<em>partially</em> tested):</p><p><pre class="brush: csharp">MethodInfo methodDateTimeParse = typeof(DateTime).GetMethod(&quot;Parse&quot;, new Type[] { typeof(string) });
var variable = Expression.Parameter(typeof(string), &quot;foo&quot;);    
Expression ExprLeft = Expression.Call(methodDateTimeParse, variable);</pre></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/db257b45bfa44b90b690a03e00c7a9a1#db257b45bfa44b90b690a03e00c7a9a1</link>
		<pubDate>Wed, 25 Apr 2012 12:06:56 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/db257b45bfa44b90b690a03e00c7a9a1#db257b45bfa44b90b690a03e00c7a9a1</guid>
		<dc:creator>Richard Anthony Hein</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Richard.Hein/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>Here's a fully tested version:</p><p><pre class="brush: csharp">MethodInfo methodDateTimeParse = typeof(DateTime).GetMethod(&quot;Parse&quot;, new Type[] { typeof(string) });
var variable = Expression.Parameter(typeof(string), &quot;foo&quot;);
Expression exprLeft = Expression.Call(methodDateTimeParse, variable);
Expression&lt;Func&lt;string, DateTime&gt;&gt; lambda = Expression.Lambda&lt;Func&lt;string, DateTime&gt;&gt; (exprLeft, variable);
Func&lt;string, DateTime&gt; func = lambda.Compile();    
DateTime dt = func(&quot;2012-04-25&quot;);
Console.WriteLine(dt);</pre></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/364d57cba7c742038856a03e00c94e49#364d57cba7c742038856a03e00c94e49</link>
		<pubDate>Wed, 25 Apr 2012 12:12:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/364d57cba7c742038856a03e00c94e49#364d57cba7c742038856a03e00c94e49</guid>
		<dc:creator>Richard Anthony Hein</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Richard.Hein/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>Hi Richard,</p><p>Thank you so much for your help.</p><p>The code which you gave that works fine with Constant which comes at the right side of the operator.</p><p>I have List&lt;Report&gt; lstReport=New&nbsp;List&lt;Report&gt;();</p><p>I want to write lstReport=lstReport.Where(o=&gt;<u><strong>DateTime.Parse(o.Field)</strong></u>==<strong>DateTime.Parse(o.FieldValue)</strong>);</p><p>I am creating above statement dynamically</p><p>like this&nbsp;</p><p>&nbsp; var variable = Expression.Variable(typeof(Report));</p><p><strong>foreach (SQWFilterConstraint oFC in oFilter.LstFilterConstraint) //usingthis collection I am making dynamic query</strong><br><strong>{</strong></p><p>&nbsp; Expression &nbsp;ExprLeft =Expression.Property(variable, oFC.Field);</p><p>MethodInfo methodDateTimeParse = typeof(DateTime).GetMethod(&quot;Parse&quot;, newType[] { typeof(string) });</p><p>var methodParam = Expression.Parameter(typeof(string), oFC.FieldValue);</p><p>Expression exprRight = Expression.Call(methodDateTimeParse, methodParam );</p><p><strong>}</strong></p><p>var props = new[] { variable };</p><p>var lambda = Expression.Lambda&lt;Func&lt;Report, bool&gt;&gt;(ExprPrev, props).Compile();</p><p>ReportList = ReportList.Where(lambda).ToList();</p><p>So Need to apply DateTime.Parse method on filed also which comes at the left side of the operator</p><p>I will be very thank full if you provide help.</p><p>Thanks in Advance&nbsp;</p><p><span><br></span></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/45254f3c300347a4bbc9a03f0071a196#45254f3c300347a4bbc9a03f0071a196</link>
		<pubDate>Thu, 26 Apr 2012 06:53:43 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/45254f3c300347a4bbc9a03f0071a196#45254f3c300347a4bbc9a03f0071a196</guid>
		<dc:creator>Somnath Sonawne</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/somnath2107/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>@<a href="/Forums/Coffeehouse/Need-help-to-build-Expression-Tree#c45254f3c300347a4bbc9a03f0071a196">somnath2107</a>:</p><p>This is the best I can do for you right now:</p><p>&nbsp;</p><p><pre class="brush: csharp">MethodInfo methodDateTimeParse = typeof(DateTime).GetMethod(&quot;Parse&quot;, new Type[] { typeof(string) });
var variable = Expression.Parameter(typeof(string), &quot;foo&quot;);
Expression exprLeft = Expression.Call(methodDateTimeParse, variable);
ConstantExpression exprRight = Expression.Constant(DateTime.Parse(&quot;2012-01-01&quot;));
BinaryExpression comparison = Expression.Equal(exprLeft, exprRight);
Expression&lt;Func&lt;string, bool&gt;&gt; lambda = Expression.Lambda&lt;Func&lt;string, bool&gt;&gt; (comparison, variable);
ConstantExpression constant = Expression.Constant (DateTime.Parse(&quot;2012-01-01&quot;));
Func&lt;string, bool&gt; func = lambda.Compile();    
bool datesUnEqual = func(&quot;2012-04-25&quot;);
Console.WriteLine(datesUnEqual);
bool datesEqual = func(&quot;2012-01-01&quot;);
Console.WriteLine(datesEqual);</pre>&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/6ce2f02d985f4d85b051a03f0125b6a8#6ce2f02d985f4d85b051a03f0125b6a8</link>
		<pubDate>Thu, 26 Apr 2012 17:49:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/6ce2f02d985f4d85b051a03f0125b6a8#6ce2f02d985f4d85b051a03f0125b6a8</guid>
		<dc:creator>Richard Anthony Hein</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Richard.Hein/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p><code class="csharp plain">var variable = Expression.Parameter(</code><code class="csharp keyword">typeof</code><code class="csharp plain">(</code><code class="csharp keyword">string</code><code class="csharp plain">), </code><code class="csharp string">&quot;foo&quot;</code><code class="csharp plain">);</code></p><p>I cant use like this because value &quot;foo&quot; should be taken from collection &nbsp;at the runtime</p><p><span>&nbsp;Expression &nbsp;ExprLeft =Expression.Property(variable, oFC.Field);</span></p><p><span>Can we apply DateTime.Parse to above expression ?</span></p><p><span><br></span></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/e7ed7bf7e41e4d0996f8a040006d4dbf#e7ed7bf7e41e4d0996f8a040006d4dbf</link>
		<pubDate>Fri, 27 Apr 2012 06:37:57 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/e7ed7bf7e41e4d0996f8a040006d4dbf#e7ed7bf7e41e4d0996f8a040006d4dbf</guid>
		<dc:creator>Somnath Sonawne</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/somnath2107/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Post Permalink" href="/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/e7ed7bf7e41e4d0996f8a040006d4dbf">6 hours&nbsp;ago</a>, <a href="/Niners/somnath2107">somnath2107</a> wrote</p><p><code class="csharp plain">var variable = Expression.Parameter(</code><code class="csharp keyword">typeof</code><code class="csharp plain">(</code><code class="csharp keyword">string</code><code class="csharp plain">), </code><code class="csharp string">&quot;foo&quot;</code><code class="csharp plain">);</code></p><p>I cant use like this because value &quot;foo&quot; should be taken from collection &nbsp;at the runtime</p><p><span>&nbsp;Expression &nbsp;ExprLeft =Expression.Property(variable, oFC.Field);</span></p><p><span>Can we apply DateTime.Parse to above expression ?</span></p><p><span><br></span></p><p></p></div></blockquote><p></p><p>Sorry I am swamped in the middle of a death march.&nbsp; I suggest you ask the rest of your questions on <a href="http://www.stackoverflow.com" target="_blank">Stackoverflow.com,&nbsp;</a>&nbsp;as you're bound to get more/better answers.</p><p>Good luck,</p><p>Richard</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/7bc5a5a0e0d94c3dad48a04000d8c316#7bc5a5a0e0d94c3dad48a04000d8c316</link>
		<pubDate>Fri, 27 Apr 2012 13:09:12 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/7bc5a5a0e0d94c3dad48a04000d8c316#7bc5a5a0e0d94c3dad48a04000d8c316</guid>
		<dc:creator>Richard Anthony Hein</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Richard.Hein/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>Am I the only one here that thinks this method of solving this problem is overkill? If you want to dynamically restrict a list of things, why not pass the list to some restriction function, based on whatever heuristics are available to you at runtime?</p><p>-Josh</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/5c23b72cf6674891b6d3a043002fb079#5c23b72cf6674891b6d3a043002fb079</link>
		<pubDate>Mon, 30 Apr 2012 02:53:37 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/5c23b72cf6674891b6d3a043002fb079#5c23b72cf6674891b6d3a043002fb079</guid>
		<dc:creator>Joshua Ross</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Jsoh/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>Am I the only one here that thinks this method of solving this problem is overkill? If you want to dynamically restrict a list of things, why not pass the list to some restriction function, based on whatever heuristics are available to you at runtime?</p><p>-Josh</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/c01d5e6e27824aa3bf13a043002fb0e6#c01d5e6e27824aa3bf13a043002fb0e6</link>
		<pubDate>Mon, 30 Apr 2012 02:53:38 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/c01d5e6e27824aa3bf13a043002fb0e6#c01d5e6e27824aa3bf13a043002fb0e6</guid>
		<dc:creator>Joshua Ross</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Jsoh/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Post Permalink" href="/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/5c23b72cf6674891b6d3a043002fb079">6 hours&nbsp;ago</a>, <a href="/Niners/JoshRoss">JoshRoss</a> wrote</p><p>Am I the only one here that thinks this method of solving this problem is overkill? If you want to dynamically restrict a list of things, why not pass the list to some restriction function, based on whatever heuristics are available to you at runtime?</p><p>-Josh</p><p></p></div></blockquote><p></p><p>Overkill is the only way some people can think to solve a problem, especially if the code is non-readable to everybody&nbsp;except to themselves of course. It usually is an ego thing to make them think they are smart. I'm not saying this is the case here, but it usually is.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/24adb5579e8b4ea2833aa04300a33688#24adb5579e8b4ea2833aa04300a33688</link>
		<pubDate>Mon, 30 Apr 2012 09:54:14 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/24adb5579e8b4ea2833aa04300a33688#24adb5579e8b4ea2833aa04300a33688</guid>
		<dc:creator>Vesuvius</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/vesuvius/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>How is it overkill? It's not a lot of code. And it will be similar nearly everytime. Expression trees are the way to create dynamic LINQ ... it's core to LINQ ... so how can you do it any easier, such that it can be serialized into an expression tree across whatever provider you are targeting?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/bf178eaf0ffb4fb8b6aea04300bc82ca#bf178eaf0ffb4fb8b6aea04300bc82ca</link>
		<pubDate>Mon, 30 Apr 2012 11:26:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/bf178eaf0ffb4fb8b6aea04300bc82ca#bf178eaf0ffb4fb8b6aea04300bc82ca</guid>
		<dc:creator>Richard Anthony Hein</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Richard.Hein/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Need help to build Expression Tree</title>
		<description><![CDATA[<p>@<a href="/Forums/Coffeehouse/Need-help-to-build-Expression-Tree#cbf178eaf0ffb4fb8b6aea04300bc82ca">Richard.Hein</a>: I could understand using dynamic LINQ, if you wanted to create a LINQ provider. But in most cases, people just want to pass around IEnumerables. Sometimes it's hard to tell the forest from the trees.</p><p>-Josh</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/1d4656ac7a8a4216a492a04300f0bc16#1d4656ac7a8a4216a492a04300f0bc16</link>
		<pubDate>Mon, 30 Apr 2012 14:36:29 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Need-help-to-build-Expression-Tree/1d4656ac7a8a4216a492a04300f0bc16#1d4656ac7a8a4216a492a04300f0bc16</guid>
		<dc:creator>Joshua Ross</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Jsoh/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>