Repository: dotnet/efcore
File: test/EFCore.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs (C#)

Code before:
        Assert.NotEqual(filterExpression3, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);

        entityBuilder.HasQueryFilter(new QueryFilter(filterKey, filterExpression, ConfigurationSource.Explicit));
        Assert.NotEqual(filterExpression2, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);
    }

    [ConditionalFact]
    public void Can_override_named_query_filter_from_convention_with_explicit_configuration()
    {
        // This test verifies that named query filters set by conventions can be overridden by explicit configuration
        var modelBuilder = CreateModelBuilder();
        var entityBuilder = modelBuilder.Entity(typeof(Order), ConfigurationSource.Explicit);

        LambdaExpression conventionFilter = (Order o) => o.Id == 1;
        LambdaExpression explicitFilter = (Order o) => o.Id == 2;
        const string filterKey = "testFilter";

        // Convention sets a named query filter
        entityBuilder.HasQueryFilter(new QueryFilter(filterKey, conventionFilter, ConfigurationSource.Convention));
        Assert.Same(conventionFilter, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);
        Assert.Equal(ConfigurationSource.Convention, entityBuilder.Metadata.GetQueryFilterConfigurationSource(filterKey));

        // Public API should be able to override it
        var publicBuilder = new EntityTypeBuilder(entityBuilder.Metadata);
        publicBuilder.HasQueryFilter(filterKey, explicitFilter);
        
        // Verify the filter was replaced with the explicit one
        Assert.Same(explicitFilter, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);
        Assert.Equal(ConfigurationSource.Explicit, entityBuilder.Metadata.GetQueryFilterConfigurationSource(filterKey));
    }

    private static TestLogger<DbLoggerCategory.Model, TestLoggingDefinitions> CreateTestLogger()
        => new() { EnabledFor = LogLevel.Warning };

    private InternalModelBuilder CreateModelBuilder(Model model = null)
        => new(model ?? new Model());

    private InternalModelBuilder CreateConventionalModelBuilder()
        => (InternalModelBuilder)InMemoryTestHelpers.Instance.CreateConventionBuilder().GetInfrastructure();

    public enum MemberType
    {
        Property,
        ComplexProperty,
        ServiceProperty,
        Navigation,
        SkipNavigation
    }

    private class Order
    {

Review comment (suggestion):
Line contains trailing whitespace on an otherwise blank line; please remove it to keep the file clean and avoid potential formatting/CI issues.
```suggestion

```

Code after:
        Assert.NotEqual(filterExpression3, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);

        entityBuilder.HasQueryFilter(new QueryFilter(filterKey, filterExpression, ConfigurationSource.Explicit));
        Assert.NotEqual(filterExpression2, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);
    }

    [ConditionalFact]
    public void Can_override_named_query_filter_from_convention_with_explicit_configuration()
    {
        // This test verifies that named query filters set by conventions can be overridden by explicit configuration
        var modelBuilder = CreateModelBuilder();
        var entityBuilder = modelBuilder.Entity(typeof(Order), ConfigurationSource.Explicit);

        LambdaExpression conventionFilter = (Order o) => o.Id == 1;
        LambdaExpression explicitFilter = (Order o) => o.Id == 2;
        const string filterKey = "testFilter";

        // Convention sets a named query filter
        entityBuilder.HasQueryFilter(new QueryFilter(filterKey, conventionFilter, ConfigurationSource.Convention));
        Assert.Same(conventionFilter, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);
        Assert.Equal(ConfigurationSource.Convention, entityBuilder.Metadata.GetQueryFilterConfigurationSource(filterKey));

        // Public API should be able to override it
        var publicBuilder = new EntityTypeBuilder(entityBuilder.Metadata);
        publicBuilder.HasQueryFilter(filterKey, explicitFilter);
        // Verify the filter was replaced with the explicit one
        Assert.Same(explicitFilter, entityBuilder.Metadata.FindDeclaredQueryFilter(filterKey).Expression);
        Assert.Equal(ConfigurationSource.Explicit, entityBuilder.Metadata.GetQueryFilterConfigurationSource(filterKey));
    }

    private static TestLogger<DbLoggerCategory.Model, TestLoggingDefinitions> CreateTestLogger()
        => new() { EnabledFor = LogLevel.Warning };

    private InternalModelBuilder CreateModelBuilder(Model model = null)
        => new(model ?? new Model());

    private InternalModelBuilder CreateConventionalModelBuilder()
        => (InternalModelBuilder)InMemoryTestHelpers.Instance.CreateConventionBuilder().GetInfrastructure();

    public enum MemberType
    {
        Property,
        ComplexProperty,
        ServiceProperty,
        Navigation,
        SkipNavigation
    }

    private class Order
    {
        public static readonly PropertyInfo IdProperty = typeof(Order).GetProperty(nameof(Id));