迁移到MVC6 / EF7:PluralizingTableNameConvention

时间:2015-08-02 13:49:07

标签: asp.net-core-mvc entity-framework-core

我将我的MVC5应用程序迁移到MVC6。目前我使用两种惯例

    public class RentABikeDbContext : DbContext
{
    ...

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    }
}

然而,在MVC6 / EF7中,新的Microsoft.Data.Entity.ModelBuilder类上没有Conventions属性。 EF7指定约定的正确方法是什么?

2 个答案:

答案 0 :(得分:2)

实体框架7没有任何内置复数,因此没有任何内容可以删除,并且尚未实现级联删除https://github.com/aspnet/EntityFramework/issues/333

答案 1 :(得分:0)

迭代所有实体,获取外键,并将它们设置为Delete Restricted:

foreach (var relationship in builder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
    relationship.DeleteBehavior = DeleteBehavior.Restrict;
}