When using OrderBy with value type, exception is thrown, for example:
System.NotSupportedException : Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.
I think this happens because OrderBy accepts Func<T, object>, which means expression with int param is boxed into an object. In case of using string property for soring, it works fine.
Maybe we should change OrderBy signature to OrderBy(Expression<Func<T,R>> criteria,...) ?
When using OrderBy with value type, exception is thrown, for example:
System.NotSupportedException : Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.
I think this happens because OrderBy accepts Func<T, object>, which means expression with int param is boxed into an object. In case of using string property for soring, it works fine.
Maybe we should change OrderBy signature to OrderBy(Expression<Func<T,R>> criteria,...) ?