nullException
nullException

Reputation: 1112

C# LINQ to Entities does not recognize the method

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 ?

Upvotes: 1

Views: 626

Answers (1)

petro.sidlovskyy
petro.sidlovskyy

Reputation: 5103

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.

Upvotes: 4

Related Questions