Answers for "entity framework delete record with foreign key constraint"

C#
0

entity framework delete record with foreign key constraint

public class FoodJournalEntities : DbContext
{
    public DbSet<Journal> Journals { get; set; }
    public DbSet<JournalEntry> JournalEntries { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Journal>()
               .HasOptional(j => j.JournalEntries)
               .WithMany()
               .WillCascadeOnDelete(true);
        base.OnModelCreating(modelBuilder);
    }
}
Posted by: Guest on June-07-2021

Code answers related to "entity framework delete record with foreign key constraint"

C# Answers by Framework

Browse Popular Code Answers by Language