InvalidOperationException: No method 'Where' on type 'System.Linq.Queryable' is compatible with the supplied arguments

后端 未结 2 1337
無奈伤痛
無奈伤痛 2021-01-19 05:11

(Code below has been updated and worked properly)

There is dynamic OrderBy sample from LinqPad. What I want to do is just simply apply \'Where\' rather than \'OrderB

2条回答
  •  礼貌的吻别
    2021-01-19 06:11

    1. Use the lambda that Jon Skeet supplied. Perhaps he can also explain why ParameterExpression is so painful to use and requires using the same instance, instead of being able to be matched by name :)

    2. Modify this line:

    Type[] exprArgTypes = { query.ElementType };
    

    exprArgTypes is type parameters to

    IQueryable Where(this IQueryable source, Expression> predicate).
    

    As you can see it only has one type parameter - TSource, which is Purchase. What you were doing, effectively, was calling Where method with two type parameters like below:

    IQueryable Where(this IQueryable source, Expression> predicate)
    

    Once both of those fixes are in the expression runs with no problem.

提交回复
热议问题