Reputation: 65
....linq code
select new OrderList
{
Requestor = f.Name,
Amount = b.TotalInclAmount,
DateOrder = b.DateOrder.ToString("dd/MM/yyyy HH:mm:ss"); // This line cause this issue
}
When I execute the above query I got the following exception.
LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.
When I search through the StackOverflow about this issue most of the answer recommended to use AsEnumerable But In my case, the table is much bigger. when i used it, it cause performance issue.
advise me to achieve this using without AsEnumerable.
Upvotes: 0
Views: 529
Reputation: 22038
You should do the presentation in the UI, not in the business layer. So, leave it as DateTime and let the UI format it. It tries to interpret the ToString
to the query, which isn't available.
You still should stick to the IQueryable<T>
and dates as datetimes, because you can add conditions to the query before it is being persist. (for example a where
on DateOrder
)
Upvotes: 2