Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework table per hierarchy error 3034

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

like image 792
user380689 Avatar asked Nov 15 '22 08:11

user380689


1 Answers

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 .

like image 161
BennyM Avatar answered Jan 07 '23 00:01

BennyM