I have a frustrating situation owing to this little quirk of EF. Here's a simple demo of the behavior. First the DB schema:
As you see, RestrictedProduct
is a special case of product, which I'm intending to make a subclass of Product
with some special code.
Now I import to an EF data model:
Oops! EF saw that RestrictedProduct
had only 2 fields, both FKs, so it mapped it as a one-to-many relationship between Product
and Restriction
. So I go back to the database and add a Dummy
field to RestrictedProduct
, and now my EF model looks much better:
But that Dummy
field is silly and pointless. Maybe I could delete it? I blow away the field from the DB table and the entity model, then refresh the model from the DB...
Oh, no! The Product-Restriction
association is back, under a new name (RestrictedProduct1
)! Plus, it won't compile:
Error 3034: Problem in mapping fragments starting at lines (x, y) :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.
Is there any way to prevent this behavior, short of keeping the Dummy
field on the RestrictedProduct
table?