Friday, 13 September 2013

Not Supported Database Function in IQueryable Query

One of the simplest ways that we could try to fix errors related to non-translatable function from EF query to its similar database function is to take that function out of the query and put in separate line(s). It might help in some cases.

For example; if we have this error "LINQ to Entities does not recognize the method 'Int64 ToInt64(System.String)' method, and this method cannot be translated into a store expression." because of the code below:
query = query.Where(x => x.StudentId.Value == Convert.ToInt64(number));
then we can try to do as below:
long value = Convert.ToInt64(number);
query = query.Where(x => x.StudentId.Value == value);

No comments: