Showing posts from May, 2016

Exception LINQ to Entities does not recognize the method ToString

Introduction This is most common exception occurs while we working with entity framework and converting data inside IQueryable result for filtering. Description Mainly full exception message as “ LINQ to Entities does not recognize the method ' System.String ToString() ' method, and this method cannot be translated into a store expression.” var result=dc.Tests.Where(i=>i.status==status.ToString()).FirstOrDefault(); This exception mainly occurs, when we query SQL database using entity framework. The problem is that you are calling ToString in a LINQ to Entities query (IQueryable to IEnumrable). That means the parser is trying to convert the ToString call into its equivalent SQL (which isn't possible...hence the exception). To solve this problem there is different solution. Solution 1:   All you have to do is move the ToString call to a separate line. String userStatus=status.ToString(); var result=dc.Tests.Where(i=>i.status== userStatus).FirstOrDefau