LINQ to Entities does not recognize method

I run into this NotSupportedException more often than I should: “LINQ to Entities does not recognize the method ‘System.String ToString()’ method, and this method cannot be translated into a store expression.” It’s a simple fix, but it always slips my mind until I run into the exception.

This is the offending code (Event.lookupCode is a string while myMeeting.Code is an int):

The exception is thrown because there is no equivalent of the ToString() method in SQL. To fix this, store the string value of the int code in a temporary variable:

This entry was posted in it and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>