private void DisableCascadeDeletes(ModelBuilder mb) { var types = mb.Model.GetEntityTypes(); foreach (var type in types) { var fkeys = type.GetForeignKeys(); foreach (var fk in fkeys) { if (!fk.IsOwnership) { fk.DeleteBehavior = DeleteBehavior.Restrict; } } } }
override void OnModelCreating(ModelBuilder mb) { // Add the next line to your code DisableCascadeDeletes(mb); // your other code goes here }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.