Skip to content

The mapping of interface member [...] is not supported

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);

To this:

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.

VN:F [1.8.3_1051]
Rating: 0.0/5 (0 votes cast)
VN:F [1.8.3_1051]
Rating: 0 (from 0 votes)
Bookmark and Share
kick it on DotNetKicks.com
Shout it

NOW, FOR A WORD FROM OUR SPONSORS

2 Comments

  1. Aasmund

    I had no idea this could make a difference – thanks a lot! Saved me from a bit of pain.

    UN:F [1.8.3_1051]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.3_1051]
    Rating: 0 (from 0 votes)
    Posted on 02-Mar-10 at 11:46 pm | Permalink
  2. Tahir Hassan

    Thank you for this, you definitely post this solution on

    http://connect.microsoft.com/VisualStudio/feedback/details/344903/linq-to-sql-mapping-interface-member-not-supported-exception

    as a workaround, so other developers can find the solution more quickly.

    Thank YOU!

    UN:F [1.8.3_1051]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.3_1051]
    Rating: 0 (from 0 votes)
    Posted on 10-Mar-10 at 11:27 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*
My name is Graham O'Neale and I'm a software architect from Gold Coast, Australia. I am an overtime thinker, full time coder and awake part time in the real world. I have a keen interest in software development, particularly in the realm of programming (C#, ASP.NET, ASP.NET MVC, LINQ (2 SQL), Entity Framework, Silverlight, Blend, WCF, WPF) and a keen interest in the cutting edge and innovation. I have a new found love for design patterns, ALT.NET practices and well crafted software architecture. The purpose of this blog is to express any thoughts, findings, tips and gripes along my travels in the wonderful world of coding and technology...