Last post Jun 21, 2018 06:36 PM by Faraz A. Qureshi
Jun 21, 2018 10:04 AM|Faraz A. Qureshi|LINK
While I was using a piece of the following quite easily, today when I have started for ASP Core 2.x I find it not working:
Upon googling I came up to find the only resolving outcome to be something like:
protected override void OnModelCreating(Modelbuilder builder)
.HasMany(c => c.SubTableConnect)
.WithOne(e => e.MainTableConnect).
Is it necessary to find and type for each Entity separately?
How to refer to every entity and either restrict OR set to null upon deletion of an entry in the parent table any info from the child tables? Obviously from the nature of info in the database I don't seek to even lose the orphan entries
unless expressly deleted via t-sql or any other method.
Jun 21, 2018 06:36 PM|Faraz A. Qureshi|LINK
Rowan Millar's praiseworthy recommended piece at https://github.com/aspnet/EntityFrameworkCore/issues/3815 did resolve the said matter, i.e.:
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
relationship.DeleteBehavior = DeleteBehavior.Restrict;
Thanks anyways friends!