I’ve created an expression that I’m using for sorting which works fine, until I hit a DateTime field, where I get the following error (on the second line):
Expression of type ‘System.DateTime’ cannot be used for return type
‘System.Object’
Here’s my code:
ParameterExpression param = Expression.Parameter(typeof(MyEntity), "x");
Expression<Func<MyEntity, object>> sortExpression =
Expression.Lambda<Func<AMyEntity, object>>(
Expression.Property(param, sortKey), param);
Can anyone help at all?
Just add a conversion in there: