< Summary - Code Coverage

Information
Class: Plainquire.Filter.EntityFilter<T>
Assembly: Plainquire.Filter
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/Filters/EntityFilter.cs
Tag: 64_13932151703
Line coverage
93%
Covered lines: 45
Uncovered lines: 3
Coverable lines: 48
Total lines: 511
Line coverage: 93.7%
Branch coverage
75%
Covered branches: 15
Total branches: 20
Branch coverage: 75%
Method coverage
100%
Covered methods: 20
Total methods: 20
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%11100%
GetPropertyFilterSyntax(...)100%11100%
GetPropertyFilterValues(...)100%11100%
GetNestedFilter(...)100%11100%
GetNestedFilter(...)100%11100%
Add(...)100%11100%
AddNested(...)50%2275%
AddNested(...)100%22100%
Replace(...)100%11100%
ReplaceNested(...)50%2275%
ReplaceNested(...)50%2275%
Remove(...)100%11100%
Clear()100%11100%
Clone()100%11100%
Cast()100%44100%
CreateFilter(...)100%11100%
op_Implicit(...)50%22100%
op_Implicit(...)50%22100%
ToString()100%44100%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/Filters/EntityFilter.cs

#LineLine coverage
 1using Plainquire.Filter.Abstractions;
 2using Plainquire.Filter.JsonConverters;
 3using Plainquire.Filter.PropertyFilterExpressions;
 4using System;
 5using System.Collections.Generic;
 6using System.Diagnostics;
 7using System.Diagnostics.CodeAnalysis;
 8using System.Linq;
 9using System.Linq.Expressions;
 10using System.Reflection;
 11using System.Text.Json;
 12using System.Text.Json.Serialization;
 13
 14namespace Plainquire.Filter;
 15
 16/// <summary>
 17/// Hub to create filter expressions for <typeparamref name="TEntity"/> with fluent API.
 18/// </summary>
 19/// <typeparam name="TEntity">The type to be filtered.</typeparam>
 20[JsonConverter(typeof(EntityFilterConverter.Factory))]
 21[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
 22public class EntityFilter<TEntity> : EntityFilter
 23{
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="EntityFilter{TEntity}"/> class.
 26    /// </summary>
 1384827    public EntityFilter() { }
 28
 29    /// <summary>
 30    /// Initializes a new instance of the <see cref="EntityFilter{TEntity}"/> class.
 31    /// </summary>
 32    /// <param name="configuration">The configuration to use.</param>
 33    public EntityFilter(FilterConfiguration configuration)
 1987034        : base(configuration) { }
 35
 36    /// <summary>
 37    /// Gets the filter syntax for the given <paramref name="property"/>.
 38    /// </summary>
 39    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 40    /// <param name="property">The property to get the filter for.</param>
 41    public string? GetPropertyFilterSyntax<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 242        => GetPropertyFilterSyntaxInternal(property);
 43
 44    /// <summary>
 45    /// Get the filters applied to the given property.
 46    /// </summary>
 47    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 48    /// <param name="property">The property to get the filter for.</param>
 49    public ValueFilter[]? GetPropertyFilterValues<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 250        => GetPropertyFilterValuesInternal(property);
 51
 52    /// <summary>
 53    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested class <typeparamref name="TProperty"/>.
 54    /// </summary>
 55    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 56    /// <param name="property">The property to get the filter for.</param>
 57    public EntityFilter<TProperty>? GetNestedFilter<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 158        => GetNestedFilterInternal(property);
 59
 60    /// <summary>
 61    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested list <typeparamref name="TList"/>.
 62    /// </summary>
 63    /// <typeparam name="TList">The type of the list of <typeparamref name="TProperty"/>.</typeparam>
 64    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 65    /// <param name="property">The property to get the filter for.</param>
 66    public EntityFilter<TProperty>? GetNestedFilter<TList, TProperty>(Expression<Func<TEntity, TList?>> property)
 67        where TList : IEnumerable<TProperty>
 168        => GetNestedFilterInternal<TEntity, TList, TProperty>(property);
 69
 70    /// <summary>
 71    /// Adds a filter for the given property. Existing filters for the same property are preserved.
 72    /// </summary>
 73    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 74    /// <param name="property">The property to filter.</param>
 75    /// <param name="filters">The filters to use.</param>
 76    public EntityFilter<TEntity> Add<TProperty>(Expression<Func<TEntity, TProperty?>> property, params ValueFilter[]? fi
 77    {
 10878        AddInternal(property, filters);
 10779        return this;
 80    }
 81
 82    /// <summary>
 83    /// Adds a nested filter for the given property. Existing filters for the same property are preserved.
 84    /// </summary>
 85    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 86    /// <param name="property">The property to filter.</param>
 87    /// <param name="nestedFilter">The nested class filter.</param>
 88    public EntityFilter<TEntity> AddNested<TProperty>(Expression<Func<TEntity, TProperty?>> property, EntityFilter<TProp
 89    {
 190        if (nestedFilter == null)
 091            return this;
 92
 193        AddNestedInternal(property, nestedFilter);
 194        return this;
 95    }
 96
 97    /// <summary>
 98    /// Adds a nested filter for the given enumerable property. Existing filters for the same property are preserved.
 99    /// </summary>
 100    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 101    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 102    /// <param name="property">The property to filter. Must implement <see cref="IEnumerable{T}"/>.</param>
 103    /// <param name="nestedFilter">The nested class filter.</param>
 104    public EntityFilter<TEntity> AddNested<TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, EntityFil
 105        where TProperty : IEnumerable<TNested>
 106    {
 7107        if (nestedFilter == null)
 6108            return this;
 109
 1110        AddNestedInternal(property, nestedFilter);
 1111        return this;
 112    }
 113
 114    /// <summary>
 115    /// Replaces the filter for the given property. Existing filters for the same property are removed.
 116    /// </summary>
 117    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 118    /// <param name="property">The property to filter.</param>
 119    /// <param name="filters">The filters to use.</param>
 120    public EntityFilter<TEntity> Replace<TProperty>(Expression<Func<TEntity, TProperty?>> property, params ValueFilter[]
 121    {
 10057122        ReplaceInternal(property, filters);
 10057123        return this;
 124    }
 125
 126    /// <summary>
 127    /// Replaces the nested filter for the given property. Existing filters for the same property are removed.
 128    /// </summary>
 129    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 130    /// <param name="property">The property to filter.</param>
 131    /// <param name="nestedFilter">The nested class filter.</param>
 132    public EntityFilter<TEntity> ReplaceNested<TProperty>(Expression<Func<TEntity, TProperty?>> property, EntityFilter<T
 133    {
 13134        if (nestedFilter == null)
 0135            return Remove(property);
 136
 13137        ReplaceNestedInternal(property, nestedFilter);
 13138        return this;
 139    }
 140
 141    /// <summary>
 142    /// Replaces the nested filter for the given enumerable property. Existing filters for the same property are removed
 143    /// </summary>
 144    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 145    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 146    /// <param name="property">The property to filter. Must implement <see cref="IEnumerable{T}"/>.</param>
 147    /// <param name="nestedFilter">The nested class filter.</param>
 148    public EntityFilter<TEntity> ReplaceNested<TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, Entit
 149        where TProperty : IEnumerable<TNested>
 150    {
 15151        if (nestedFilter == null)
 0152            return Remove(property);
 153
 15154        ReplaceNestedInternal(property, nestedFilter);
 15155        return this;
 156    }
 157
 158    /// <summary>
 159    /// Remove all filters for the specified property.
 160    /// </summary>
 161    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 162    /// <param name="property">The property to remove all filters for.</param>
 163    public EntityFilter<TEntity> Remove<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 164    {
 11165        RemoveInternal(property);
 11166        return this;
 167    }
 168
 169    /// <summary>
 170    /// Removes all filters of all properties.
 171    /// </summary>
 172    public EntityFilter<TEntity> Clear()
 173    {
 1174        ClearInternal();
 1175        return this;
 176    }
 177
 178    /// <summary>
 179    /// Creates a deep clone of this filter.
 180    /// </summary>
 181    public new EntityFilter<TEntity> Clone()
 3352182        => JsonSerializer.Deserialize<EntityFilter<TEntity>>(JsonSerializer.Serialize(this))!;
 183
 184    /// <summary>
 185    /// Casts this filter to a different type (by creating a deep clone).
 186    /// Filtered properties are matched by type (check if assignable) and name (case-sensitive).
 187    /// </summary>
 188    /// <typeparam name="TDestination">The type of the destination entity to filter.</typeparam>
 189    public EntityFilter<TDestination> Cast<TDestination>()
 190    {
 8191        var castFilter = JsonSerializer.Deserialize<EntityFilter<TDestination>>(JsonSerializer.Serialize(this))!;
 8192        var sourceProperties = typeof(TEntity).GetProperties();
 8193        var destinationProperties = typeof(TDestination).GetProperties().ToList();
 194
 80195        foreach (var sourceProperty in sourceProperties)
 196        {
 32197            var sameDestinationPropertyExists = destinationProperties
 32198                .Exists(x =>
 32199                    x.Name.EqualsOrdinal(sourceProperty.Name) &&
 32200                    x.PropertyType.IsAssignableFrom(sourceProperty.PropertyType)
 32201                );
 202
 32203            if (!sameDestinationPropertyExists)
 204            {
 9205                castFilter.PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(sourceProperty.Name));
 9206                castFilter.NestedFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(sourceProperty.Name));
 207            }
 208        }
 209
 8210        return castFilter;
 211    }
 212
 213    /// <summary>
 214    /// Creates the filter expression. Returns <c>null</c> when filter is empty.
 215    /// </summary>
 216    /// <param name="interceptor">An interceptor to manipulate the generated filters.</param>
 217    /// <param name="useAsCompiledExpression">Whether the generated expression will be compiled later. Used to determine
 218    public Expression<Func<TEntity, bool>>? CreateFilter(IFilterInterceptor? interceptor = null, bool useAsCompiledExpre
 18157219        => CreateFilter<TEntity>(interceptor, useAsCompiledExpression);
 220
 221    /// <summary>
 222    /// Performs an implicit conversion from <see cref="EntityFilter{TEntity}"/> to <see cref="Expression{TDelegate}"/> 
 223    /// </summary>
 224    /// <param name="filter">The filter to convert.</param>
 225    public static implicit operator Expression<Func<TEntity, bool>>(EntityFilter<TEntity> filter)
 1226        => filter.CreateFilter(useAsCompiledExpression: false) ?? (x => true);
 227
 228    /// <summary>
 229    /// Performs an implicit conversion from <see cref="EntityFilter{TEntity}"/> to <see cref="Func{T, TResult}"/>.
 230    /// </summary>
 231    /// <param name="filter">The filter to convert.</param>
 232    public static implicit operator Func<TEntity, bool>(EntityFilter<TEntity> filter)
 8233        => (filter.CreateFilter(useAsCompiledExpression: true) ?? (x => true)).Compile();
 234
 235    /// <inheritdoc />
 236    public override string ToString()
 38237        => CreateFilter()?.ToString() ?? string.Empty;
 238
 239    [ExcludeFromCodeCoverage]
 240    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 241    private string DebuggerDisplay => CreateFilter()?.ToString() ?? "<EMPTY>";
 242}
 243
 244/// <inheritdoc cref="EntityFilter{TEntity}" />
 245[JsonConverter(typeof(EntityFilterConverter))]
 246public class EntityFilter : ICloneable
 247{
 248    private static readonly MethodInfo _createFilterMethod = typeof(EntityFilter).GetMethods(BindingFlags.Instance | Bin
 249
 250    internal List<PropertyFilter> PropertyFilters;
 251    internal List<NestedFilter> NestedFilters;
 252
 253    /// <summary>
 254    /// Gets or sets the default configuration. Can be used to set a system-wide configuration.
 255    /// </summary>
 256    public FilterConfiguration? Configuration { get; internal set; }
 257
 258    /// <summary>
 259    /// Initializes a new instance of the <see cref="EntityFilter"/> class.
 260    /// </summary>
 261    public EntityFilter()
 262    {
 263        PropertyFilters = [];
 264        NestedFilters = [];
 265    }
 266
 267    /// <summary>
 268    /// Initializes a new instance of the <see cref="EntityFilter"/> class.
 269    /// </summary>
 270    /// <param name="configuration">The configuration to use.</param>
 271    public EntityFilter(FilterConfiguration configuration)
 272        : this()
 273        => Configuration = configuration;
 274
 275    /// <inheritdoc />
 276    public object Clone()
 277        => JsonSerializer.Deserialize<EntityFilter>(JsonSerializer.Serialize(this))!;
 278
 279    /// <summary>
 280    /// Indicates whether this filter is empty.
 281    /// </summary>
 282    public bool IsEmpty() => !PropertyFilters.Any() && !NestedFilters.Any();
 283
 284    /// <summary>
 285    /// Gets the filter syntax for the given <typeparamref name="TProperty"/>.
 286    /// </summary>
 287    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 288    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 289    /// <param name="property">The property to get the filter for.</param>
 290    protected string? GetPropertyFilterSyntaxInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property
 291    {
 292        var propertyName = property.GetPropertyName();
 293        var propertyFilter = PropertyFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName));
 294        return ValueFilterExtensions.ToString(propertyFilter?.ValueFilters);
 295    }
 296
 297    /// <summary>
 298    /// Get the filters applied to the given property.
 299    /// </summary>
 300    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 301    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 302    /// <param name="property">The property to get the filter for.</param>
 303    protected ValueFilter[]? GetPropertyFilterValuesInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> p
 304    {
 305        var propertyName = property.GetPropertyName();
 306        return PropertyFilters.FirstOrDefault(predicate => predicate.PropertyName.EqualsOrdinal(propertyName))?.ValueFil
 307    }
 308
 309    /// <summary>
 310    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested class <typeparamref name="TProperty"/>.
 311    /// </summary>
 312    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 313    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 314    /// <param name="property">The property to get the filter for.</param>
 315    protected EntityFilter<TProperty>? GetNestedFilterInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>>
 316    {
 317        var propertyName = property.GetPropertyName();
 318        return (EntityFilter<TProperty>?)NestedFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName))?.
 319    }
 320
 321    /// <summary>
 322    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested list <typeparamref name="TList"/>.
 323    /// </summary>
 324    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 325    /// <typeparam name="TList">The type of the list of <typeparamref name="TProperty"/>.</typeparam>
 326    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 327    /// <param name="property">The property to get the filter for.</param>
 328    protected EntityFilter<TProperty>? GetNestedFilterInternal<TEntity, TList, TProperty>(Expression<Func<TEntity, TList
 329        where TList : IEnumerable<TProperty>
 330    {
 331        var propertyName = property.GetPropertyName();
 332        return (EntityFilter<TProperty>?)NestedFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName))?.
 333    }
 334
 335    /// <summary>
 336    /// Adds a filter for the given property. Existing filters for the same property are preserved.
 337    /// </summary>
 338    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 339    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 340    /// <param name="property">The property to filter.</param>
 341    /// <param name="valueFilters">The filters to use.</param>
 342    protected void AddInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property, ValueFilter[]? valueF
 343    {
 344        var propertyName = property.GetPropertyName();
 345        PropertyFilters.Add(new PropertyFilter(propertyName, valueFilters));
 346    }
 347
 348    /// <summary>
 349    /// Adds a nested filter for the given property. Existing filters for the same property are preserved.
 350    /// </summary>
 351    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 352    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 353    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 354    /// <param name="property">The property to filter.</param>
 355    /// <param name="nestedFilter">The nested class filter.</param>
 356    protected void AddNestedInternal<TEntity, TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, Entity
 357    {
 358        var propertyName = property.GetPropertyName();
 359        NestedFilters.Add(new NestedFilter(propertyName, nestedFilter));
 360    }
 361
 362    /// <summary>
 363    /// Replaces the filter for the given property using the default filter operator. Existing filters for the same prop
 364    /// </summary>
 365    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 366    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 367    /// <param name="property">The property to filter.</param>
 368    /// <param name="valueFilters">The filters to use.</param>
 369    protected void ReplaceInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property, ValueFilter[]? va
 370    {
 371        var propertyName = property.GetPropertyName();
 372        PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 373        PropertyFilters.Add(new PropertyFilter(propertyName, valueFilters));
 374    }
 375
 376    /// <summary>
 377    /// Replaces the nested filter for the given property. Existing filters for the same property are removed.
 378    /// </summary>
 379    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 380    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 381    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 382    /// <param name="property">The property to filter.</param>
 383    /// <param name="nestedFilter">The nested class filter.</param>
 384    protected void ReplaceNestedInternal<TEntity, TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, En
 385    {
 386        var propertyName = property.GetPropertyName();
 387        NestedFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 388        NestedFilters.Add(new NestedFilter(propertyName, nestedFilter));
 389    }
 390
 391    /// <inheritdoc cref="EntityFilter{TEntity}.Remove{TProperty}(Expression{Func{TEntity, TProperty}})" />
 392    protected void RemoveInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property)
 393    {
 394        var propertyName = property.GetPropertyName();
 395        PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 396    }
 397
 398    /// <inheritdoc cref="EntityFilter{TEntity}.Clear" />
 399    protected void ClearInternal()
 400        => PropertyFilters.Clear();
 401
 402    /// <inheritdoc cref="EntityFilter{TEntity}.CreateFilter" />
 403    protected internal Expression<Func<TEntity, bool>>? CreateFilter<TEntity>(IFilterInterceptor? interceptor, bool useA
 404    {
 405        var configuration = Configuration ?? FilterConfiguration.Default ?? new FilterConfiguration();
 406        interceptor ??= IFilterInterceptor.Default;
 407
 408        var properties = typeof(TEntity).GetProperties();
 409        var useConditionalAccess = UseConditionalAccess(configuration, useAsCompiledExpression);
 410
 411        var propertyFilters = GetPropertyFilters<TEntity>(properties, interceptor, configuration);
 412        var nestedObjectFilters = GetNestedObjectFilters<TEntity>(properties, useConditionalAccess, interceptor, useAsCo
 413        var nestedListsFilters = CreateNestedListFilters<TEntity>(properties, useConditionalAccess, interceptor, useAsCo
 414
 415        return propertyFilters
 416            .Concat(nestedObjectFilters)
 417            .Concat(nestedListsFilters)
 418            .CombineWithConditionalAnd();
 419    }
 420
 421    private List<Expression<Func<TEntity, bool>>?> GetPropertyFilters<TEntity>(PropertyInfo[] properties, IFilterInterce
 422        => properties
 423            .Reverse()
 424            .Join(
 425                PropertyFilters,
 426                x => x.Name,
 427                x => x.PropertyName,
 428                (propertyInfo, propertyFilter) => new { Property = propertyInfo, propertyFilter.ValueFilters },
 429                StringComparer.Ordinal
 430            )
 431            .Select(x =>
 432                interceptor?.CreatePropertyFilter<TEntity>(x.Property, x.ValueFilters, configuration)
 433                ?? PropertyFilterExpression.CreateFilter<TEntity>(x.Property, x.ValueFilters, configuration, interceptor
 434            )
 435            .ToList();
 436
 437    private List<Expression<Func<TEntity, bool>>?> GetNestedObjectFilters<TEntity>(PropertyInfo[] properties, bool useCo
 438    {
 439        return properties
 440            .Reverse()
 441            .Where(x => !x.PropertyType.IsGenericIEnumerable())
 442            .Join(
 443                NestedFilters,
 444                x => x.Name,
 445                x => x.PropertyName,
 446                (propertyInfo, nestedFilter) => new { Property = propertyInfo, nestedFilter.EntityFilter },
 447                StringComparer.Ordinal
 448            )
 449            .Select(x =>
 450            {
 451                var createFilterExpression = _createFilterMethod.MakeGenericMethod(x.Property.PropertyType);
 452                var nestedFilterExpression = (LambdaExpression?)createFilterExpression.Invoke(x.EntityFilter, [intercept
 453                if (nestedFilterExpression == null)
 454                    return null;
 455
 456                var propertySelector = typeof(TEntity).CreatePropertySelector(x.Property.Name);
 457                var propertyMatchesNested = (Expression<Func<TEntity, bool>>)nestedFilterExpression.ReplaceParameter(pro
 458
 459                if (!useConditionalAccess)
 460                    return propertyMatchesNested;
 461
 462                var propertyIsNotNull = propertySelector.IsNotNull(x.Property.PropertyType);
 463                var propertyIsNotNullLambda = propertySelector.CreateLambda<TEntity, bool>(propertyIsNotNull);
 464
 465                var filterExpression = new[] { propertyIsNotNullLambda, propertyMatchesNested }.CombineWithConditionalAn
 466                return filterExpression;
 467            })
 468            .ToList();
 469    }
 470
 471    private List<Expression<Func<TEntity, bool>>?> CreateNestedListFilters<TEntity>(PropertyInfo[] properties, bool useC
 472        => properties
 473            .Reverse()
 474            .Where(x => x.PropertyType.IsGenericIEnumerable())
 475            .Join(
 476                NestedFilters,
 477                x => x.Name,
 478                x => x.PropertyName,
 479                (propertyInfo, nestedFilter) => new { Property = propertyInfo, nestedFilter.EntityFilter },
 480                StringComparer.Ordinal
 481            )
 482            .Select(x =>
 483            {
 484                var propertyType = x.Property.PropertyType.GetGenericArguments()[0];
 485                var createFilterExpression = _createFilterMethod.MakeGenericMethod(propertyType);
 486                var nestedFilterExpression = (LambdaExpression?)createFilterExpression.Invoke(x.EntityFilter, [intercept
 487                if (nestedFilterExpression == null)
 488                    return null;
 489
 490                var propertySelector = typeof(TEntity).CreatePropertySelector(x.Property.Name);
 491                var propertyHasAnyNested = (Expression<Func<TEntity, bool>>)propertySelector.EnumerableAny(propertyType,
 492
 493                if (!useConditionalAccess)
 494                    return propertyHasAnyNested;
 495
 496                var propertyIsNotNull = propertySelector.IsNotNull(x.Property.PropertyType);
 497                var propertyIsNotNullLambda = propertySelector.CreateLambda<TEntity, bool>(propertyIsNotNull);
 498
 499                var filterExpression = new[] { propertyIsNotNullLambda, propertyHasAnyNested }.CombineWithConditionalAnd
 500                return filterExpression;
 501            })
 502            .ToList();
 503
 504    private static bool UseConditionalAccess(FilterConfiguration configuration, bool usedAsCompiledExpression)
 505        => configuration.UseConditionalAccess switch
 506        {
 507            FilterConditionalAccess.Always => true,
 508            FilterConditionalAccess.Never => false,
 509            _ => usedAsCompiledExpression
 510        };
 511}