A random spillage of programming (and other) thoughts

Entity Framework Error 3002 / Error 3003

Posted by Michael Bray on October 14, 2008

Fun problem I had today figuring out this error….  I suppose it is common, and in fact I think I recall reading posts on Usenet about this, without many solutions.  The problem comes when you have a mapping from one table to another. 

The error in this case comes in the form of two errors during compile:

Error 3002: Problem in Mapping Fragment starting at line 498: Potential runtime violation of table QuotePricedLineItem’s keys (QuotePricedLineItem.ObjectId): Columns (QuotePricedLineItem.ObjectId) are mapped to EntitySet FK_QuoteLineItem_QuoteVendorLineSet’s properties (FK_QuoteLineItem_QuoteVendorLineSet.QuoteVendorLineSet.ObjectId) on the conceptual side but they do not form the EntitySet’s key properties (FK_QuoteLineItem_QuoteVendorLineSet.QuotePricedLineItem.ObjectId, FK_QuoteLineItem_QuoteVendorLineSet.QuoteVendorLineSet.ObjectId).

Error 3003: Problem in Mapping Fragment starting at line 498: At least one of the key properties of AssociationSet FK_QuoteLineItem_QuoteVendorLineSet must be mapped to all the key properties (QuotePricedLineItem.ObjectId) of table QuotePricedLineItem.

This clearly sounds like there is a problem in the association between two tables.  Looking at the designer diagram, you see the relation:


and looking at the mappings of the association, at first glance, everything looks fine:


The problem lies in which column is mapped to which property.  In this case, and I believe generally in the case of this particular error, the columns are interchanged.  The mappings should be QuoteVendorLineSet.ObjectId = fkQuoteVendorLineSet, and QuotePricedLineItem.ObjectId = ObjectId.  This is obvious since the map is for QuotePricedLineItem, so ObjectId should map to itself.

The odd part is that this association was generated by the EF Designer wizard, so it is the one that screwed up.  At first I thought maybe I had the relationship backwards in the database, but that wasn’t the case.  Thus I’m not sure why this occurred, but tracking it down hopefully will be easier next time.


2 Responses to “Entity Framework Error 3002 / Error 3003”

  1. I had this error come up to, but because my primary key had changed. Even though the database schema had been updated, and the model was updated, it didn’t updated what it thought was the primary key.

  2. Thomas Liao said

    I have found the same error occurs when the set of key columns differs between the database schema and the entity definition. In my case, if found that two additional items in the mapping had been set as being part of the primary key for the entity set.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: