Entity Framework Core cascade delete one to many relationship

前端 未结 2 1285
灰色年华
灰色年华 2020-12-15 22:01
public class Station : IEntitie
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public virtual ICollection         


        
2条回答
  •  心在旅途
    2020-12-15 22:46

    Described "problem" is not related to Entity Framework - this is restriction of MS SQL Server itself. Table with several FKs may have only one of them with cascade delete.

    So, as soon as you need both FKs to have cascade - you should implement such "cleanup" in your code. Set one (or both) FKs to DeleteBehavior.Restrict, and in your controller/service prior to removing Station manually find and delete all related RegulatorySchedule

提交回复
热议问题