Entity Framework - Foreign key constraints not added for inherited entity
Posted
by Tri Q
on Stack Overflow
See other posts from Stack Overflow
or by Tri Q
Published on 2010-05-25T02:56:12Z
Indexed on
2010/05/25
3:01 UTC
Read the original article
Hit count: 389
entity-framework
|self-tracking-entities
Hello,
It appears to me that a strange phenomenon is occurring with inherited entities (TPT) in EF4.
I have three entities. 1. Asset 2. Property 3. Activity
Property is a derived-type of Asset. Property has many activities (many-to-many)
When modeling this in my EDMX, everything seems fine until I try to insert a new Property into the database. If the property does not contain any Activity, it works, but all hell breaks loose when I add some new activities to the new Property.
As it turns out after 2 days of crawling the web and fiddling around, I noticed that in the EF store (SSDL) some of the constraints between entities were not picked up during the update process.
Property_Activity table which links properties and activities show only one constraint FK_Property_Activity_Activity but FK_Property_Activity_Property was missing.
I knew this is an Entity Framework anomoly because when I switched the relationship in the database to:
Asset <--> Asset_Activity <--> Activity
After an update, all foreign key constraints are picked up and the save is successful, with or without activities in the new property.
Is this intended or a bug in EF?
How do I get around this problem?
Should I abandon inheritance altogether?
© Stack Overflow or respective owner