OK, check out the following simple object model:
- Entity
ConcreteThingy
derives fromAbstractThingy
. - Entity
Owner
can have at most 1ConcreteThingy
.- No two
Owners
can have the sameConcreteThingy
.
- No two
EDMX:
DB model (TPT):
What I want:
I want 2 things, in descending order of priority:
- Thing I want #1: Above all, I want the simplest, most concise, cleaner solution to #2 below.
- Thing I want #2: When I delete an
Owner
, I want to automatically delete any potentially associatedConcreteThingy
, along with the baseAbstractThingy
.
What I'm doing:
So, naturally, I went to the EDMX and simply turned on Cascade delete on the Owner 0 ↔ 0..1 ConcreteThingy association.
This works well in setting the Delete rule of the FK_ConcreteThingy_Owner
relationship to Cascade, but I don't see ANY constraints/DB code that makes sure that the AbstractThingy
record gets deleted as well.
Again, when I delete an Owner
, the corresponding ConcreteThingy
(if any) is deleted, but it leaves the dangling AbstractThingy
, which not surprisingly, I don't want.
Can somebody please tell me what is the standard way to implement this type of tasks using EF 5?
I've tried by making AbstractThingy
abstract, hoping that the SQL code would somehow infer what I want (understandably there would be some sort of chicken-and-egg conundrum for the generator, but hey, at least I tried it.)
Or should I define some sort of smart-ass referential constraint in my EDMX?
Or is it expected that I'd go to the DB and write code myself, like a trigger, etc...!?!? That would be a bit of a[nother] fiasco for EF and its design tools.
Thanks.