youtu.be ASP.NET Core Tutorialの動画のCascade Deleteの回の最後で紹介されてた. OnModelCreatingメソッド内でDbContextの外部キーを収集し,それらのDeleteBehaviorを設定する. protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); foreach (var foreignKey in modelBuilder.Model.GetEntityTypes() .SelectMany(e => e.GetForeignKeys())) { foreignKey.DeleteBehavior = DeleteBehavior.Restrict; } } 他にもCasca
![DbContext内のすべてのDbSetに一括でDeleteBehaviorを設定する - shuhelohelo’s blog](https://cdn-ak-scissors.b.st-hatena.com/image/square/726eb7607eec55080161b387b906fc107c6d8ad2/height=288;version=1;width=512/https%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fs%2Fshuhelohelo%2F20191113%2F20191113124255.png)