Skip to content

Commit 1e6ecd0

Browse files
committed
Store null index filters
Fixes #20136
1 parent e2074e9 commit 1e6ecd0

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static string GetFilter([NotNull] this IIndex index)
8686
/// <param name="index"> The index. </param>
8787
/// <param name="value"> The value to set. </param>
8888
public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] string value)
89-
=> index.SetOrRemoveAnnotation(
89+
=> index.SetAnnotation(
9090
RelationalAnnotationNames.Filter,
9191
Check.NullButNotEmpty(value, nameof(value)));
9292

@@ -97,7 +97,7 @@ public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] str
9797
/// <param name="value"> The value to set. </param>
9898
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
9999
public static void SetFilter([NotNull] this IConventionIndex index, [CanBeNull] string value, bool fromDataAnnotation = false)
100-
=> index.SetOrRemoveAnnotation(
100+
=> index.SetAnnotation(
101101
RelationalAnnotationNames.Filter,
102102
Check.NullButNotEmpty(value, nameof(value)),
103103
fromDataAnnotation);

test/EFCore.Relational.Tests/Metadata/RelationalMetadataBuilderExtensionsTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,27 @@ public void Can_access_index()
155155

156156
Assert.Null(indexBuilder.HasName("Splod"));
157157
Assert.Equal("Splow", indexBuilder.Metadata.GetName());
158+
159+
Assert.NotNull(indexBuilder.HasName(null, fromDataAnnotation: true));
160+
Assert.Equal("IX_Splot_Id", indexBuilder.Metadata.GetName());
161+
162+
Assert.NotNull(indexBuilder.HasName("Splod"));
163+
Assert.Equal("Splod", indexBuilder.Metadata.GetName());
164+
165+
Assert.NotNull(indexBuilder.HasFilter("Splew"));
166+
Assert.Equal("Splew", indexBuilder.Metadata.GetFilter());
167+
168+
Assert.NotNull(indexBuilder.HasFilter("Splow", fromDataAnnotation: true));
169+
Assert.Equal("Splow", indexBuilder.Metadata.GetFilter());
170+
171+
Assert.Null(indexBuilder.HasFilter("Splod"));
172+
Assert.Equal("Splow", indexBuilder.Metadata.GetFilter());
173+
174+
Assert.NotNull(indexBuilder.HasFilter(null, fromDataAnnotation: true));
175+
Assert.Null(indexBuilder.Metadata.GetFilter());
176+
177+
Assert.Null(indexBuilder.HasFilter("Splod"));
178+
Assert.Null(indexBuilder.Metadata.GetFilter());
158179
}
159180

160181
[ConditionalFact]

test/EFCore.Relational.Tests/Metadata/RelationalMetadataExtensionsTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ public void Can_get_and_set_index_filter()
4242
{
4343
var modelBuilder = new ModelBuilder(new ConventionSet());
4444

45-
var property = modelBuilder
45+
var index = modelBuilder
4646
.Entity<Customer>()
4747
.HasIndex(e => e.Id)
4848
.HasFilter("[Id] % 2 = 0")
4949
.Metadata;
5050

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

53-
property.SetFilter("[Id] % 3 = 0");
53+
index.SetFilter("[Id] % 3 = 0");
5454

55-
Assert.Equal("[Id] % 3 = 0", property.GetFilter());
55+
Assert.Equal("[Id] % 3 = 0", index.GetFilter());
5656
}
5757

5858
[ConditionalFact]

0 commit comments

Comments
 (0)