Or two 式に静的関数を書き込もうとしていますが、次のエラーが表示されます。
パラメータ 'item' はスコープ外です。
説明: 現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。
例外の詳細: System.InvalidOperationException: パラメーター 'item' はスコープ内にありません。
メソッド:
public static Expression<Func<T, bool>> OrExpressions(Expression<Func<T, bool>> left, Expression<Func<T, bool>> right)
{
// Define the parameter to use
var param = Expression.Parameter(typeof(T), "item");
var filterExpression = Expression.Lambda<Func<T, bool>>
(Expression.Or(
left.Body,
right.Body
), param);
// Build the expression and return it
return (filterExpression);
}
編集:さらに情報を追加
or'd されている式は、以下のメソッドから取得されており、正常に実行されます。より良い方法や結果があれば、私はすべて耳にします。また、事前にどれだけの数が実行中または実行中かわかりません。
public static Expression<Func<T, bool>> 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<Func<T, bool>>
(Expression.Equal(
Expression.Convert(Expression.Property(param, filterBy), typeof(TVal)),
Expression.Constant(Value)
),
param);
// Build the expression and return it
return (filterExpression);
}
編集:さらに情報を追加する
または、or を実行するより良い方法はありますか? 現在、.Where(constraint) は、制約が Expression> 型の場合に問題なく機能します。どこで(制約1または制約2)(制約n番目まで)を行うにはどうすればよいですか
前もって感謝します!