📜  实体框架删除具有外键约束的记录 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:21.434000             🧑  作者: Mango

代码示例1
public class FoodJournalEntities : DbContext
{
    public DbSet Journals { get; set; }
    public DbSet JournalEntries { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity()
               .HasOptional(j => j.JournalEntries)
               .WithMany()
               .WillCascadeOnDelete(true);
        base.OnModelCreating(modelBuilder);
    }
}