I was working with LINQ to SQL today to bind some data to a drop down list in ASP.NET MVC, when I encountered this strange exception I’ve never seen before:
System.NotSupportedException: The mapping of interface member IDbTable.StatusID is not supported.
I figured I knew what triggered the problem, and that being due to the new interface I have all my LINQ to SQL entities implement from as to perform some generic query logic in my repository, the IDbTable.
But what I still didn’t know, is why I was receiving this error.
After some careful research, it appears that in the code construct where I build the query, I was performing a conditional test with equal signs (==) instead of the Equals() method. Very strange, but as Philipp quoted, even though it results in the same SQL query executing, one throws an NotSupportedException and one does not!
So all I had to do was to change:
return GetAll().Where(x => x.StatusID == (int)status);
return GetAll().Where(x => x.StatusID.Equals((int)status));
and I was all set.
This is going to make me closely think twice about EVER using the double equals in LINQ to SQL again.