Skip to content

Commit

Permalink
Store null index filters
Browse files Browse the repository at this point in the history
Fixes #20136
  • Loading branch information
AndriySvyryd committed Mar 4, 2020
1 parent e2074e9 commit 1e6ecd0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
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

0 comments on commit 1e6ecd0

Please sign in to comment.