samy
samy

Reputation: 14962

Entity Framework 4.1 Codefirst: delete many to many children when they have no parents

In Nhibernate, it's possible to have an object declared a responsible for a many to many relationship. It's also possible to declare the realtionship as deleting the "child" object if it has no parents. So if A1 is linked to B1 and B2, and A2 is linked to B2, deleting A1 will also delete B1, but not B2.

I'd like to know if this behavior is configurable in EF 4 or if i have to manually check the child relationship.

Upvotes: 1

Views: 261

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

EF offers only basic cascade delete which works only for deleting dependent records when principal is deleted. In your scenario you need to delete principal record if dependent is deleted and no other dependent exists.

As I know EF doesn't offer any similar feature and it would require many other features to be added before this one can be considered. The problem is that even cascade delete is performed through database - EF doesn't create any special SQL command for it.

Upvotes: 1

Related Questions