Skip to content

Commit

Permalink
Added index for MetadataEntries on Key Include Value for joins
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovan Crone committed Jan 11, 2019
1 parent babb80c commit c6ec807
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasMaxLength(450)
.IsRequired();

modelBuilder.Entity<MetadataEntry>()
.HasIndex(entry => entry.Key);

modelBuilder.Entity<StateBagEntry>()
.HasKey(entry => new
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace REstate.EntityFrameworkCore.Migrations.SqlServer.Migrations
{
public partial class IndexMetadataEntriesKey : Migration
{
private const string SqlServer = "Microsoft.EntityFrameworkCore.SqlServer";

protected override void Up(MigrationBuilder migrationBuilder)
{
if (migrationBuilder.ActiveProvider == SqlServer)
{
migrationBuilder.Sql(@"CREATE NONCLUSTERED INDEX IX_MetadataEntries_Key
ON [dbo].[MetadataEntries] ([Key])
INCLUDE ([Value])");
}
else
{
migrationBuilder.CreateIndex(
name: "IX_MetadataEntries_Key",
table: "MetadataEntries",
column: "Key");
}
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_MetadataEntries_Key",
table: "MetadataEntries");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MachineId", "Key");

b.HasIndex("Key");

b.ToTable("MetadataEntries");
});

Expand Down

0 comments on commit c6ec807

Please sign in to comment.