Add Index with Include Entity Framework Core

This post explaines how to add index to EF Core with extra columns included from code.

When creating indexes with code first migrations in Entity Framework Core you can create an index on a table by adding the following to your DbContext:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);

    modelBuilder.Entity<table>() 
        .HasIndex(t =&gt; new { t.Column1, t.Column2}); } 

Continue reading “Add Index with Include Entity Framework Core”

Advertisement