IQueryable.Where() suitable Expression in where?

后端 未结 4 1291
自闭症患者
自闭症患者 2021-01-03 02:05

I\'m very low experienced with Expressions in .NET, that\'s why I rather ask you guys. How should I - see comment below:

using P = Myclass;
..
S         


        
4条回答
  •  旧时难觅i
    2021-01-03 02:44

    .Where method takes a lambda expression as a parameter, so you need to build your BinaryExpression to a complete LambdaExpression.

    var resultExpression = Expression.OrElse(myExp1, myExp2);   
       // now the exp is like: p > 100 || p < 10
    ParameterExpression parameterExp = Expression.Parameter(typeof(P),"p");
       // construct a parameter with its type P, looks like: p =>
    LambdaExpression lambdaExp = Expression.Lambda(resultExpression, parameterExp);
       // merge the two expressions:  p => p > 100 || p < 10
    myList.Where(lambdaExp.Compile());
    

提交回复
热议问题