Have problem with linq expressions.
I want to get from db some data ordered by datetime. Early there was sorting by string field.
Sorting expression (by string):
Expression<Func<Matter, Object>> result = e => e.MatterNumber;
//In debug mode: {e => e.MatterNumber}
Works fine
Sorting expression (by datetime or int):
Expression<Func<Matter, Object>> result = e => e.Created;
//In debug mode: {{e => Convert(e.Created)}}
This rise an error: {“Unable to cast the type ‘System.Int32’ to type ‘System.Object’. LINQ to Entities only supports casting Entity Data Model primitive types.”}
Please help 🙂
alexei, you might wanna take a look at this SO Question:
Entity Framework: LINQ to Entities only supports casting Entity Data Model primitive types
or this one here:
Help me understand "LINQ to Entities only supports casting Entity Data Model primitive types"
and finally on SO:
Entityframework 4.0 .CreateQuery<T> and OrderBy exception
and on the forums.asp.net:
http://forums.asp.net/t/1580414.aspx/1
all 4 deal with this issue in slightly differing ways but hopefully will be helpful in your scenario.