views:

195

answers:

1

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.

  1. Is this intended or a bug in EF?

  2. How do I get around this problem?

  3. Should I abandon inheritance altogether?

+1  A: 
  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.

John Hartsock
I sometimes just delete the edmx file and recreate it.
Jack Marchetti
yeah i have had to do that before too after the designer added more crap than i needed. It was easier to go back to the beginning than to try to make rhyme or reason out of what the designer added and omitted.
John Hartsock
Is this something that the MS team is going to improve on if any cares to speculate? A good example is Designer in RC adding StoreGenerated ="Identity" to linking entities.
Tri Q
I imagine they will work on the designer some more but the truth is, the power is in the framework itself and the framework is very well designed.
John Hartsock