首页 > 解决方案 > 防止在 EF Core 3.1 代码优先中创建非聚集索引

问题描述

在 EF Core 中,默认情况下,它为代码优先方法的外键创建非聚集索引。

我想防止在 EF Core 3.1 中的外键上创建非聚集索引。

在实体框架“经典”(不是核心)中,我可以这样做,就像删除这样的ForeignKeyIndexConvention约定:

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

但是,我不能在 EF Core 中执行此操作,它不会运行代码。

最好的方法是什么?

标签: c#entity-framework-coreforeign-keysef-core-3.1non-clustered-index

解决方案


推荐阅读