EntityFramework.DiscriminatorIndex 1.0.0.3

Help us to create index on discriminator columns.

Install-Package EntityFramework.DiscriminatorIndex -Version 1.0.0.3
dotnet add package EntityFramework.DiscriminatorIndex --version 1.0.0.3
<PackageReference Include="EntityFramework.DiscriminatorIndex" Version="1.0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFramework.DiscriminatorIndex --version 1.0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

EntityFramework.DiscriminatorIndex

Help us to create index on discriminator columns by generating migration index operations (create, rename and drop).

Setup

Migration Configuration file:

internal sealed class Configuration : DbMigrationsConfiguration<DbContext>
{
    public Configuration()
    {
        this.AddSupportToDiscriminatorIndex();
    }
}

DbConfiguration:

public class DbConfiguration : System.Data.Entity.DbConfiguration
{
    public DbConfiguration()
    {
        SetMetadataAnnotationSerializer(
            DiscriminatorIndexAnnotation.AnnotationName,
            () => new DiscriminatorIndexAnnotationSerializer());
    }
}

##How To Use?

Entity Type Configuration

To configure the index for a type, use the extention method HasIndexOnDiscriminator() of the EntityTypeConfiguration:

public class DbContext: System.Data.Entity.DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<MyEntity>().HasIndexOnDiscriminator();
        base.OnModelCreating(modelBuilder);
    }
}

Optionally, we can customize inform the column name, and also set the index name.

modelBuilder.Entity<MyEntity>().HasIndexOnDiscriminator(
    columnName: "MyDiscriminator", 
    indexName: "IX_Entity_Discriminator");

Convention

Using the convention, all columns named as "Discriminator" in the database will be indexed.

public class DbContext: System.Data.Entity.DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Add<DiscriminatorIndexConvention>();
        base.OnModelCreating(modelBuilder);
    }
}

Optionally, we can provide an alternative column name to search for:

modelBuilder.Conventions.Add(new DiscriminatorIndexConvention(discriminatorColumnName: "CustoDiscriminator"));

When using the convention, we can also ignore some entity:

modelBuilder.Entity<MyEntity>()
    .HasTableAnnotation(DiscriminatorIndexAnnotation.AnnotationName, null);

... or yet replace the default convention using the HasIndexOnDiscriminator extension method.

EntityFramework.DiscriminatorIndex

Help us to create index on discriminator columns by generating migration index operations (create, rename and drop).

Setup

Migration Configuration file:

internal sealed class Configuration : DbMigrationsConfiguration<DbContext>
{
    public Configuration()
    {
        this.AddSupportToDiscriminatorIndex();
    }
}

DbConfiguration:

public class DbConfiguration : System.Data.Entity.DbConfiguration
{
    public DbConfiguration()
    {
        SetMetadataAnnotationSerializer(
            DiscriminatorIndexAnnotation.AnnotationName,
            () => new DiscriminatorIndexAnnotationSerializer());
    }
}

##How To Use?

Entity Type Configuration

To configure the index for a type, use the extention method HasIndexOnDiscriminator() of the EntityTypeConfiguration:

public class DbContext: System.Data.Entity.DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<MyEntity>().HasIndexOnDiscriminator();
        base.OnModelCreating(modelBuilder);
    }
}

Optionally, we can customize inform the column name, and also set the index name.

modelBuilder.Entity<MyEntity>().HasIndexOnDiscriminator(
    columnName: "MyDiscriminator", 
    indexName: "IX_Entity_Discriminator");

Convention

Using the convention, all columns named as "Discriminator" in the database will be indexed.

public class DbContext: System.Data.Entity.DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Add<DiscriminatorIndexConvention>();
        base.OnModelCreating(modelBuilder);
    }
}

Optionally, we can provide an alternative column name to search for:

modelBuilder.Conventions.Add(new DiscriminatorIndexConvention(discriminatorColumnName: "CustoDiscriminator"));

When using the convention, we can also ignore some entity:

modelBuilder.Entity<MyEntity>()
    .HasTableAnnotation(DiscriminatorIndexAnnotation.AnnotationName, null);

... or yet replace the default convention using the HasIndexOnDiscriminator extension method.

Release Notes

Update to NET Standard 2.1 and EntityFramework 6.3.0

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0.3 3,224 1/27/2020
1.0.0.2 14,424 1/4/2017
1.0.0.1 470 10/20/2016