Note that there are some explanatory texts on larger screens.

plurals
  1. POExpression.Or, The parameter 'item' is not in scope
    primarykey
    data
    text
    <p>I am trying to write a static function to Or two expressions, but recieve the following error:</p> <blockquote> <p>The parameter 'item' is not in scope.</p> <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p> <p>Exception Details: System.InvalidOperationException: The parameter 'item' is not in scope.</p> </blockquote> <p>the method:</p> <pre><code>public static Expression&lt;Func&lt;T, bool&gt;&gt; OrExpressions(Expression&lt;Func&lt;T, bool&gt;&gt; left, Expression&lt;Func&lt;T, bool&gt;&gt; right) { // Define the parameter to use var param = Expression.Parameter(typeof(T), "item"); var filterExpression = Expression.Lambda&lt;Func&lt;T, bool&gt;&gt; (Expression.Or( left.Body, right.Body ), param); // Build the expression and return it return (filterExpression); } </code></pre> <p><strong>edit</strong>: adding more info</p> <p>The expressions being or'd are coming from the method below, which execute just fine. if there is a better way to or the results I am all ears. Also, I do not know how many are being or'd in advance.</p> <pre><code>public static Expression&lt;Func&lt;T, bool&gt;&gt; FilterExpression(string filterBy, object Value, FilterBinaryExpression binaryExpression) { // Define the parameter to use var param = Expression.Parameter(typeof(T), "item"); // Filter expression on the value switch (binaryExpression) { case FilterBinaryExpression.Equal: { // Build an expression for "Is the parameter equal to the value" by employing reflection var filterExpression = Expression.Lambda&lt;Func&lt;T, bool&gt;&gt; (Expression.Equal( Expression.Convert(Expression.Property(param, filterBy), typeof(TVal)), Expression.Constant(Value) ), param); // Build the expression and return it return (filterExpression); } </code></pre> <p><strong>edit</strong>: adding even more info</p> <p>Alternatively, is there a better way to do an or? Currently the .Where(constraint) works just fine where constraint is of type Expression>. How can i do where(constraint1 or constraint2) (to the constraint n'th)</p> <p>Thanks in advance!</p>
    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.
 

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