Filter on Table-Index ignored
JStarkl opened this issue · 2 comments
JStarkl commented
I have indices with filter values, but those won't be generated (SQLServer)
An index looks like this:
UNIQUE NONCLUSTERED INDEX [IX_person] ON [dat].[person] ([person_id] ASC)
WHERE ([primary_flag] = (1) AND [inactive_flag] = (0))
Will generate:
builder.HasIndex(x => new { x.PersonId })
.HasDatabaseName("IX_person")
.IsUnique()
But the expected result is:
builder.HasIndex(x => new { x.PersonId })
.HasFilter("([primary_flag]=(1) AND [inactive_flag]=(0))")
.HasDatabaseName("IX_person")
.IsUnique()
I checked EF.Reverse.POCO.v3.ttinclude and it seems this is not implemented.
I currently use version 3.8.0 with a EFCore7 Model
Best regards,
Jürgen
JStarkl commented
I did a quick hack for my current purposes, and the "HasFilter"-Attribute perfectly does it's Job
EF.Revers.POCO.v3.ttinclude in the method [IndexModelBuilder]:
From:
if (indexesForName.Count > 1)
sb.Append(" }");
sb.Append(")"); // Close bracket for HasIndex()
sb.Append(isEfCore5Plus ? ".HasDatabaseName(\"" : ".HasName(\"");
sb.Append(indexName);
sb.Append("\")");
To:
if (indexesForName.Count > 1)
sb.Append(" }");
sb.Append(")"); // Close bracket for HasIndex()
//>>>
if (indexName == "IX_person_email_person_id_primary" | indexName == "IX_person_phone_person_id_primary")
{
sb.Append(".HasFilter(\"([primary_flag]=(1) AND [inactive_flag]=(0))\")");
}
//<<<
sb.Append(isEfCore5Plus ? ".HasDatabaseName(\"" : ".HasName(\"");
sb.Append(indexName);
sb.Append("\")");
sjh37 commented
Your if statement should change from a single | to a double ||
if (indexName == "IX_person_email_person_id_primary" || indexName == "IX_person_phone_person_id_primary")