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.
My type definitions were wrong, as the error suggested.
typeof(TSource)
had to be typeof(TNav)
, since we are ordering source.Gifts
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With