1

LINQ to Entities does not recognize the method 'Int64 getCount()' method, and this method cannot be translated into a store expression.

return query.OrderBy(e => e.Person.getCount(), sortDirection);

how can I rewrite this line ?

nullException
  • 1,102
  • 2
  • 17
  • 26

1 Answers1

4

Please use:

return query.ToList().OrderBy(e => e.Person.getCount(), sortDirection);

The case is EF tries to convert getCount() method to SQL. As it's custom method it can't be done so you should call ToList() to evaluate the expression and to make EF load objects from database to memory. Then linq can call you custom function to sort the data.

petro.sidlovskyy
  • 4,889
  • 1
  • 23
  • 28