Bug description
We're in the process of upgrading to EF 10. We have a Convention Set that automatically adds query filters to certain types. We are switching this over to named query filters and have noticed that once the convention sets the filter (with Configuration Source == Convention) that a user cannot override the filter with the same name explicitly
I think this is because of the difference in the code for adding global and named filters:
This code sets the configuration source explicitly:
|
public virtual EntityTypeBuilder HasQueryFilter(LambdaExpression? filter) |
|
{ |
|
Builder.HasQueryFilter(filter, ConfigurationSource.Explicit); |
|
|
|
return this; |
|
} |
While this code only calls the QueryFilter constructor and never sets a configuration source.
|
public virtual EntityTypeBuilder HasQueryFilter(string filterKey, LambdaExpression? filter) |
|
{ |
|
Builder.HasQueryFilter(new QueryFilter(filterKey, filter)); |
|
|
|
return this; |
|
} |
Later on when performing CanSetQueryFilter, the configuration source on the new (explicit) filter is null and thus the old one wins.
Is this intended or is it a bug?
Your code
In a convention:
IConventionEntityTypeBuilder builder = ...;
builder.HasQueryFilter("SomeName", Expression.Lambda(...));
In a user provided configuration:
EntityTypeBuilder<SomeType> builder = ...;
builder.HasQueryFilter("SomeName", s => ...); // <--- doesn't override
See: #37708 (comment) for a full reproduction
EF Core version
10.0.3
Target framework
.NET 10
Bug description
We're in the process of upgrading to EF 10. We have a Convention Set that automatically adds query filters to certain types. We are switching this over to named query filters and have noticed that once the convention sets the filter (with Configuration Source == Convention) that a user cannot override the filter with the same name explicitly
I think this is because of the difference in the code for adding global and named filters:
This code sets the configuration source explicitly:
efcore/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs
Lines 809 to 814 in 4b56ce2
While this code only calls the
QueryFilterconstructor and never sets a configuration source.efcore/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs
Lines 823 to 828 in 4b56ce2
Later on when performing
CanSetQueryFilter, the configuration source on the new (explicit) filter is null and thus the old one wins.Is this intended or is it a bug?
Your code
In a convention:
In a user provided configuration:
See: #37708 (comment) for a full reproduction
EF Core version
10.0.3
Target framework
.NET 10