Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend to an expression
    primarykey
    data
    text
    <p>I followed this thread: <a href="https://stackoverflow.com/questions/1266742/append-to-an-expression-linq-c">link text</a></p> <p>Jason gives an example:</p> <pre><code>public static Expression&lt;TDelegate&gt; AndAlso&lt;TDelegate&gt;(this Expression&lt;TDelegate&gt; left, Expression&lt;TDelegate&gt; right) { return Expression.Lambda&lt;TDelegate&gt;(Expression.AndAlso(left, right), left.Parameters); } </code></pre> <p>and its usage as such:</p> <pre><code>Expression&lt;Func&lt;Client, bool&gt;&gt; clientWhere = c =&gt; true; if (filterByClientFName) { clientWhere = clientWhere.AndAlso(c =&gt; c.ClientFName == searchForClientFName); } if (filterByClientLName) { clientWhere = clientWhere.AndAlso(c =&gt; c.ClientLName == searchForClientLName); } </code></pre> <p>I have a orders table and i followed the above example, changing column names, and i get the similar error that the post creator had</p> <blockquote> <p>The binary operator AndAlso is not defined for the types 'System.Func<code>2[Models.Order,System.Boolean]' and 'System.Func</code>2[Models.Order,System.Boolean]'.</p> </blockquote> <p>Anyone have any thoughts on what I am missing?</p> <p>UPDATED:</p> <p>Eric, I further followed what the user of the previous post was asking, here <a href="https://stackoverflow.com/questions/1263565/dynamic-join-in-linq-0-c">link text</a></p> <p>The user has this</p> <pre><code>Expression&lt;Func&lt;Client, bool&gt;&gt; clientWhere = c =&gt; true; Expression&lt;Func&lt;Order, bool&gt;&gt; orderWhere = o =&gt; true; Expression&lt;Func&lt;Product, bool&gt;&gt; productWhere = p =&gt; true; if (filterByClient) { clientWhere = c =&gt; c.ClientID == searchForClientID; } </code></pre> <p>Now if he were to have various conditions in <code>filterByClient</code>, say he either has <code>clientid</code> and/or some other column name, how would one build the <code>clientWhere</code> expression?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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