Actually, it fails for
Expression of type 'System.Int32' cannot be used for return type 'System.Object'
The immediate issue is that you need a conversion (a box in this case) from a value-type to an
var mySortExpression = Expression.Lambda<Func<ObjectToOrder, object>>( Expression.Convert( Expression.Property(param, field), typeof(object) ), param);
object here could in-and-of-itself be problematic. I suggest looking at Dynamic LINQ OrderBy on IEnumerable<T>
- Dynamic Lambda Expression builder crashes on enumerates
- Dynamic lambda using an expression builder for select
- passing dynamic expression to order by in code first EF repository
- "Does Not Contain" dynamic lambda expression
- Dynamic Lambda Expression call
- How to write a dynamic Lambda Expression to access Nth Parent entity?
- Build dynamic linq to Sql lambda expression
- Dynamic Lambda Expression inside an Expression Query
- Dynamic lambda expression for ICollection column
- Lambda Expression for Many to Many realtionship in C# EF 5 Code First
- Dynamic lambda expression (OrderBy) and nullable property type
- Like search for datetime fields using dynamic lambda expression
- How to create dynamic lambda based Linq expression from a string in C#?
- Build lambda expression (predicate) with dynamic comparison operators
- Dynamic Lambda Expression For Filtering
- How to write the same code using Lambda Expression
- How to write following code in lambda expression or linq?
- return dynamic object with all child nodes as Json in - error: cannot use a lambda expression as an argument to a dynamically dispatched
- Lambda Expression for dynamic Object
- Prepare Dynamic Lambda Expression with Checking parentproperty null control
- ForEach loop with Lambda expression in Razor code MVC 5 For List<T>
- VS Code Coverage won't recognize only possible Expression Lambda Path
- Dynamic Linq Where with Lambda Expression generates Error
- how to create dynamic query using Lambda expression
- Creating dynamic Lambda from Existing Lambda Expression
- Lambda expression with statement body error in previously working code
- Dynamic lambda expression for array property filter
- Dynamic lambda expression for SingleOrDefault
- How do I create and populate a dynamic object using a dynamically built lambda expression
- How to create a dynamic lambda expression based on two models?
- Database and program organization in c#
- Dynamically projecting with LINQ
- If I expose IQueryable from my service layer, wouldn't the database calls be less if I need to grab information from multiple services?
- How to OrderBy on a generic IEnumerable (IEnumerable<T>) using LINQ in C#?
- Merge lists into one
- Does IEnumerable<T> store a function to be called later?
- how to write a Precompiled query?
- Return two types that derive from the same abstract class
- Same SQL query is fast or slow depending on execution context
- Why is IEnumerable.Count() reevaluating the query?
- Using async with Entity Framework select list of type IQueryable<T>
- Select rows based on group by counts
- LINQ: How to convert query results during select?
- Select 2 elements with linq
- use linq to write new file
- Linq order by with cast as
- replacing value only from an Xelement using linq
- ASP.net gridview paging index disappear when i change the page index
- Join and Group in LINQ
- VB Linq Group Join query FAILS to order the results in descending order