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.