Skip to content

Store null index filters #20158

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static string GetFilter([NotNull] this IIndex index)
/// <param name="index"> The index. </param>
/// <param name="value"> The value to set. </param>
public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] string value)
=> index.SetOrRemoveAnnotation(
=> index.SetAnnotation(
RelationalAnnotationNames.Filter,
Check.NullButNotEmpty(value, nameof(value)));

Expand All @@ -97,7 +97,7 @@ public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] str
/// <param name="value"> The value to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetFilter([NotNull] this IConventionIndex index, [CanBeNull] string value, bool fromDataAnnotation = false)
=> index.SetOrRemoveAnnotation(
=> index.SetAnnotation(
RelationalAnnotationNames.Filter,
Check.NullButNotEmpty(value, nameof(value)),
fromDataAnnotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ public void Can_access_index()

Assert.Null(indexBuilder.HasName("Splod"));
Assert.Equal("Splow", indexBuilder.Metadata.GetName());

Assert.NotNull(indexBuilder.HasName(null, fromDataAnnotation: true));
Assert.Equal("IX_Splot_Id", indexBuilder.Metadata.GetName());

Assert.NotNull(indexBuilder.HasName("Splod"));
Assert.Equal("Splod", indexBuilder.Metadata.GetName());

Assert.NotNull(indexBuilder.HasFilter("Splew"));
Assert.Equal("Splew", indexBuilder.Metadata.GetFilter());

Assert.NotNull(indexBuilder.HasFilter("Splow", fromDataAnnotation: true));
Assert.Equal("Splow", indexBuilder.Metadata.GetFilter());

Assert.Null(indexBuilder.HasFilter("Splod"));
Assert.Equal("Splow", indexBuilder.Metadata.GetFilter());

Assert.NotNull(indexBuilder.HasFilter(null, fromDataAnnotation: true));
Assert.Null(indexBuilder.Metadata.GetFilter());

Assert.Null(indexBuilder.HasFilter("Splod"));
Assert.Null(indexBuilder.Metadata.GetFilter());
}

[ConditionalFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public void Can_get_and_set_index_filter()
{
var modelBuilder = new ModelBuilder(new ConventionSet());

var property = modelBuilder
var index = modelBuilder
.Entity<Customer>()
.HasIndex(e => e.Id)
.HasFilter("[Id] % 2 = 0")
.Metadata;

Assert.Equal("[Id] % 2 = 0", property.GetFilter());
Assert.Equal("[Id] % 2 = 0", index.GetFilter());

property.SetFilter("[Id] % 3 = 0");
index.SetFilter("[Id] % 3 = 0");

Assert.Equal("[Id] % 3 = 0", property.GetFilter());
Assert.Equal("[Id] % 3 = 0", index.GetFilter());
}

[ConditionalFact]
Expand Down