MVC 3 EF 4.1 dbContext - Deleting one-to-many data object with non-nullable foreign-key relation

前端 未结 4 1130
梦毁少年i
梦毁少年i 2021-02-07 11:46

I am using MVC 3, EF 4.1, and dbContext. I need to know how to delete an entity in one-to-many relation with a non-nullable foreign-key.

When I Remove the child entity

4条回答
  •  别那么骄傲
    2021-02-07 12:31

    You can configure the relation to cascade ... this will propagate the delete to dependent entities.

    But it's very dangerous :)

    I prefer setting a flag in the row that prevents the data tier from including it in future queries, most applications do not need physical delete (and will be a chance to undo).

提交回复
热议问题