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.9.10_1130]
Rating: 5.0/5 (5 votes cast)
VN:F [1.9.10_1130]
Rating: +3 (from 3 votes)
The mapping of interface member [...] is not supported, 5.0 out of 5 based on 5 ratings
Bookmark and Share
kick it on DotNetKicks.com
Shout it

NOW, FOR A WORD FROM OUR SPONSORS

5 Comments

  1. Aasmund

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

    VA:F [1.9.10_1130]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.10_1130]
    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!

    VA:F [1.9.10_1130]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.10_1130]
    Rating: 0 (from 0 votes)
    Posted on 10-Mar-10 at 11:27 pm | Permalink
  3. John Hilts

    Thanks for posting that.

    I just wonder if that .Object method involves boxing/unboxing at all?

    VA:F [1.9.10_1130]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.10_1130]
    Rating: 0 (from 0 votes)
    Posted on 24-Nov-10 at 6:13 pm | Permalink
  4. Saved my ass! thanks!

    VA:F [1.9.10_1130]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.10_1130]
    Rating: 0 (from 0 votes)
    Posted on 30-Apr-11 at 12:14 am | Permalink
  5. Randall Eike

    I was just about to give up and dump my Generic class when I found this post. Thank you!

    VA:F [1.9.10_1130]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.10_1130]
    Rating: 0 (from 0 votes)
    Posted on 03-Aug-11 at 3:09 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...