I wanna create an Expression<Func<IQueryable<T>, IOrderedQueryable<T>>>, I have the following codes :
Expression selector = q => q.RegistrationDate
MethodInfo orderByMethodInfo = typeof(Queryable).GetMethods().First(method => method.Name == "OrderBy" && method.GetParameters().Count() == 2).MakeGenericMethod(argumentTypes);
MethodInfo orderByDescMethodInfo = typeof(Queryable).GetMethods().First(method => method.Name == "OrderByDescending" && method.GetParameters().Count() == 2).MakeGenericMethod(argumentTypes);
I'm gonna create c => c.OrderBy(q => q.RegistrationDate) or c => c.OrderByDescending(q => q.RegistrationDate) or generally something like c => c.OrderByDescending(q => q.RegistrationDate).ThenBy(q=>q.Name) from above codes.
Could you please guide how I can do it?
Where
Tis the type with theRegistrationDateproperty in yourselectorexpression.You can get the queryable type from the argument type using
MakeGenericType: