score:2
Accepted answer
actually, it fails for age
too:
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 object
:
var mysortexpression = expression.lambda<func<objecttoorder, object>>(
expression.convert(
expression.property(param, field),
typeof(object)
), param);
however, using object
here could in-and-of-itself be problematic. i suggest looking at dynamic linq orderby on ienumerable<t>
Source: stackoverflow.com
Related Query
- 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?
More Query from same tag
- How to group by and sum in linq when expressions in sum are string?
- How do you get the properties, operators and values from an Expression<Func<T, bool>> predicate?
- VB.NET LINQ join Distinct 2 tables
- C# - How to do multiple contains filters on an object list
- LINQ PredicateBuilder multiple OR starting with PredicateBuilder.True<>
- how to get child single records based on multiple condition having multiple child nodes c# linq or xpath
- Check if all values are equal in a list
- Common filtering logic in WCF query interceptors using interface
- does using "from" more than once is equivalent to have join?
- Why does IEnumerable's Where pass first argument as "this"
- List with dates, times and a string ref
- linq join with groupby and max issues
- Convert LINQ Expression to SQL Text without DB Context
- IQueryable with only optional parameters
- How to count how many fields in a JObject that are set with LINQ?
- Linq: Select Most Recent Record of Each Group
- Custom extension methods on IEnumerable<T>
- Find item from generic list
- How can I return a custom class from a web service?
- ChoETL nested JSON to CSV
- Getting data from multiple tables (C# Entity), linked by foreign keys, converted to anonymous object
- Adding primary key on datatable
- GroupBy two variables, one of them is from a nested list
- Formatting within Entity Framework Where Clause
- How can I create a LINQ statement that does a count of a joined table?
- Using Lambda expression from a separate class in SELECT clause of LINQ query c# Projection
- How can I use Linq in a T4 template?
- how to get a Linq select value from dynamic?
- How to query if array is null or empty using MongoDB and C# Driver?
- Runtime error on casting Array to string Enumerator