Preventing to create non-clustered index in EF Core 3.1 code-first

Viewed 141

In EF Core, by default, it creates a non-clustered index for a foreign key for code-first approach.

I want to prevent creating non-clustered index on the foreign key in the EF Core 3.1.

In Entity Framework "classic" (not Core), I could to do it like remove the ForeignKeyIndexConvention convention like this:

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

But, I can't do this in EF Core, it doesn't run the code.

What is the best approach to do it?

0 Answers
Related