diff --git a/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs b/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs index ef562c8b837..9935a17ce80 100644 --- a/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs +++ b/src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs @@ -539,7 +539,11 @@ protected override Expression VisitConditional(ConditionalExpression conditional goto case StateType.ContainsEvaluatable; case StateType.ContainsEvaluatable: - // The case where the test is evaluatable has been handled above + if (testState.IsEvaluatable) + { + test = ProcessEvaluatableRoot(test, ref testState); + } + if (ifTrueState.IsEvaluatable) { ifTrue = ProcessEvaluatableRoot(ifTrue, ref ifTrueState); diff --git a/test/EFCore.Specification.Tests/Query/AdHocQueryFiltersQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/AdHocQueryFiltersQueryTestBase.cs index 7daf62777ff..8c24c6d3ab4 100644 --- a/test/EFCore.Specification.Tests/Query/AdHocQueryFiltersQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/AdHocQueryFiltersQueryTestBase.cs @@ -730,4 +730,42 @@ public class ChildFilter2 } #endregion + + #region 35111 + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Query_filter_with_context_accessor_with_constant(bool async) + { + var contextFactory = await InitializeAsync(); + using var context = contextFactory.CreateContext(); + + var data = async + ? await context.Set().ToListAsync() + : context.Set().ToList(); + } + + protected class Context35111(DbContextOptions options) : DbContext(options) + { + public int Foo { get; set; } + public long? Bar { get; set; } + public List Baz { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasQueryFilter(e => + Foo == 1 + ? Baz.Contains(e.Bar) + : e.Bar == Bar); + } + } + + public class FooBar35111 + { + public long Id { get; set; } + public long Bar { get; set; } + } + + #endregion }