Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are talking about the <code>Dynamic LINQ</code> library.</p> <p>If you have VS 2008 installed you can find a detailed API document at</p> <pre><code>&lt;path to vs2008&gt;\Samples\1033\CSharpSamples\LinqSamples\DynamicQuery\Dynamic Expressions.html </code></pre> <p>Or download from <a href="http://msdn.microsoft.com/en-us/vcsharp/bb894665.aspx" rel="nofollow">here</a></p> <p>Here's the <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" rel="nofollow">Scott Gu's article on Dynamic LINQ</a></p> <p>Here's an extract from <code>Dynamic Expressions.html</code> file.</p> <h2>Current Instance</h2> <p>When parsing a lambda expression with a single unnamed parameter, the members of the unnamed parameter are automatically in scope in the expression string, and the current instance given by the unnamed parameter can be referenced in whole using the keyword it. For example,</p> <pre><code>customers.Where("Country = @0", country); </code></pre> <p>is equivalent to</p> <pre><code>customers.Where("it.Country = @0", country); </code></pre> <p>The IQueryable extension methods all parse their expression arguments as lambda expressions with a single unnamed parameter.</p> <h2>Dynamic Lambda Invocation</h2> <p>An expression can reference other dynamic lambda expressions through dynamic lambda invocations. A dynamic lambda invocation consists of a substitution variable identifier that references an instance of System.Linq.Expressions.LambdaExpression, followed by an argument list. The arguments supplied must be compatible with the parameter list of the given dynamic lambda expression.</p> <p>The following parses two separate dynamic lambda expressions and then combines them in a predicate expression through dynamic lambda invocations:</p> <pre><code>Expression&lt;Func&lt;Customer, bool&gt;&gt; e1 = DynamicExpression.ParseLambda&lt;Customer, bool&gt;("City = \"London\""); Expression&lt;Func&lt;Customer, bool&gt;&gt; e2 = DynamicExpression.ParseLambda&lt;Customer, bool&gt;("Orders.Count &gt;= 10"); IQueryable&lt;Customer&gt; query = db.Customers.Where("@0(it) and @1(it)", e1, e2); </code></pre> <p>It is of course possible to combine static and dynamic lambda expressions in this fashion:</p> <pre><code>Expression&lt;Func&lt;Customer, bool&gt;&gt; e1 = c =&gt; c.City == "London"; Expression&lt;Func&lt;Customer, bool&gt;&gt; e2 = DynamicExpression.ParseLambda&lt;Customer, bool&gt;("Orders.Count &gt;= 10"); IQueryable&lt;Customer&gt; query = db.Customers.Where("@0(it) and @1(it)", e1, e2); </code></pre> <p>The examples above both have the same effect as:</p> <pre><code>IQueryable&lt;Customer&gt; query = db.Customers.Where(c =&gt; c.City == "London" &amp;&amp; c.Orders.Count &gt;= 10); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload