5
votes

I have an Entity Framework model using table per hierarchy. The base class is abstract and there are two derived classes.

I want to create associations between these two derived classes and another class. These are many-to-many relations so go through a joining table.

Adding the first association is ok, but when I add the second i get this error:

Error 3034: Problem in mapping fragments starting at lines 1074, 1082:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.

Heres an image of relevant parts of the model (the LabelImages and PresetImages associations are the ones giving the trouble):

alt text

1
ahh someone with the same thing as me - don't suppose you found an answer.Jeff Martin

1 Answers

1
votes

A bit late but anyhow:

This is not really possible if you relate to the underlying database. Entity framework will create one join table for the association between the image table and the product table while you actually need two different ones.

I suggest using either a different option for your inheritance hierarcy in the database. Or put the relation between Image and Product, not the subtypes. You can add methods on the product class to filter on a specific type, one for presetimages one for labelimages. Or add a method on your context class to retrieve a particular type of images for a product using OfType .