Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 432
Michiel Cornille Avatar asked Nov 13 '22 00:11

Michiel Cornille


1 Answers

My type definitions were wrong, as the error suggested.

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

like image 144
Michiel Cornille Avatar answered Nov 14 '22 22:11

Michiel Cornille