Nate
Nate

Reputation: 2084

Entity Framework 4.1: Cascade Delete Database First

I have added Cascade Delete to my database but I do not see this update in my model. How do I make sure that my model has cascade delete enabled for a database first model?

Upvotes: 1

Views: 2158

Answers (1)

percebus
percebus

Reputation: 847

If the cascade delete is set on the database then you have nothing to worry about. Deleting the main Object would translate on

  1. EF telling the DB "delete entity -foo-"
  2. DB checking all the dependencies for table -foo(s)-
  3. DB deleting first all records for -foo-.ID in all dependent tables
  4. DB finally deleting -foo-.ID in table -foo(s)-

It would be more cumbersome if you only had the cascade delete on the Model but not the Database, as that would mean the EntityFramework try to figure out all of the above on runtime.

If you really want to ensure the cascade delete, you could enable it in both layers, although it doesn't sound like a good idea to me as some data "might disappear" (because it was cascade deleted) from the EF state manager.

Upvotes: 2

Related Questions