Question

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.

  1. Is this intended or a bug in EF?

  2. How do I get around this problem?

  3. Should I abandon inheritance altogether?

Was it helpful?

Solution

  1. Not a but but a poor visual designer.
  2. Its generally best to simply manage the Entity XML by hand.
  3. No inheritance works well for many situations.

Basically I use the update from database in the visual designer but knowing that the designer has its quirks. I have simply used the update from database to stub out the basics of what I want. Then I go into the Entity XML my self and clean it up the way I want. Just of note Complex types are a pain with the designer. If you plan to use complex types get ready to learn your Entity XML well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top