开发者

Entity Framework 4.1: Cascade Delete Database First

开发者 https://www.devze.com 2023-03-21 13:36 出处:网络
I hav开发者_高级运维e 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?If the cascad

I hav开发者_高级运维e 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消