Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you use the language-builting LINQ syntax, you're implicitly declaring a lamba expression - and <em>that</em> lamba expression is an <code>Expression&lt;Func &lt;&gt;&gt;</code> - so you don't need the where clause to <em>return</em> the Expression, you need it to <em>be</em> the expression.</p> <p>e.g.</p> <pre><code>var q = from row in myTable where row.a &lt; aMax select row.b; // which translates to var q = myTable.Where(row =&gt; row.a &lt; aMax).Select(row =&gt; row.b); </code></pre> <p>Now you need to "cache" <code>row =&gt; row.a &lt; aMax</code> - not just the <em>value</em> of <code>row.a &lt; aMax</code>, if you will. So, if you were to write something like this...</p> <pre><code>Expression&lt;Func&lt;?,bool&gt;&gt; cachedExpression = row =&gt; row.a &lt; aMax; var q = from row in myTable where cachedExpression select row.b; </code></pre> <p>Well, you're saying "where, given a row, it is true that (given a row, it is true that row.a is less than aMax)". This is nonsense, and won't compile if cachedExpression is of type <code>Expression&lt;Func&lt;?,bool&gt;&gt;</code> and myTable is a LinqToSql provided table. It would translate to something like this:</p> <pre><code>Expression&lt;Func&lt;?,bool&gt;&gt; cachedExpression = row =&gt; row.a &lt; aMax; //nonsense .Where: var q = myTable.Where(row =&gt; cachedExpression).Select(row =&gt; row.b); //effectively says this: var q = myTable.Where(row =&gt; (row0 =&gt; row0.a &lt; aMax)).Select(row =&gt; row.b); </code></pre> <p>Now, this is <em>legal</em> in the sense that it is <em>possible</em> for a linq query provider to implement a whereclause with a non-boolean value, but it's a very odd thing to do; certainly no standard linq providers (such as Linq to Sql) do such a thing.</p> <p>So what <em>should</em> you do? Something like:</p> <pre><code>//not .Where(row=&gt;cachedExpression)! var q = myTable.Where(cachedExpression).Select(row =&gt; row.b); //or, alternatively: var q = from filteredRow in myTable.Where(cachedExpression) select filteredRow.b; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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