No generic method 'OrderBy' on type 'Queryable' is compatible with the supplied type arguments

﹥>﹥吖頭↗ 提交于 2020-01-14 09:32:15

问题


I'm writing some code that will modify an expression so that the subquery contained in it will get ordered.

I found a similar piece of code here on SO, but it's not working for me. I also tried looking at this answer, but I'm not able to apply this to my piece of code

No generic method 'OrderBy' on type 'Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

MethodCallExpression orderByCallExpression = Expression.Call(
    typeof(Queryable),
    "OrderBy"/*Descending*/,
    new Type[] { typeof(TSource), filterpart.OrderOverPropertyGetterValueType },
    navigationalProperty.Body,
    filterpart.OrderOverPropertyGetter);                            

I'm trying to figure out which of the 2 type parameters or 2 other arguments is causing this error.

  • OrderOverPropertyGetterValueType is just typeof(DateTime) in this case
  • TSource is an Entity Type (Gifts)
  • navigationalProperty.Body contains {source.Gifts.AsQueryable()} with expression type: System.Linq.Expressions.MethodCallExpression
  • filterpart.OrderOverPropertyGetter contains {g => g.Date} with expression type System.Linq.Expressions.Expression<System.Func<Gift,System.DateTime>>

I'm clueless how to diagnose which of the four parameters is incorrect. I'm thinking one of the expression types may be incorrect.


回答1:


My type definitions were wrong, as the error suggested.

typeof(TSource) had to be typeof(TNav), since we are ordering source.Gifts.



来源:https://stackoverflow.com/questions/17943024/no-generic-method-orderby-on-type-queryable-is-compatible-with-the-supplied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!