Skip to content

Commit c41f581

Browse files
committed
Fix query filters with context accessors (#35237)
1 parent 1a71476 commit c41f581

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,11 @@ protected override Expression VisitConditional(ConditionalExpression conditional
539539
goto case StateType.ContainsEvaluatable;
540540

541541
case StateType.ContainsEvaluatable:
542-
// The case where the test is evaluatable has been handled above
542+
if (testState.IsEvaluatable)
543+
{
544+
test = ProcessEvaluatableRoot(test, ref testState);
545+
}
546+
543547
if (ifTrueState.IsEvaluatable)
544548
{
545549
ifTrue = ProcessEvaluatableRoot(ifTrue, ref ifTrueState);

test/EFCore.Specification.Tests/Query/AdHocQueryFiltersQueryTestBase.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,4 +730,42 @@ public class ChildFilter2
730730
}
731731

732732
#endregion
733+
734+
#region 35111
735+
736+
[ConditionalTheory]
737+
[MemberData(nameof(IsAsyncData))]
738+
public virtual async Task Query_filter_with_context_accessor_with_constant(bool async)
739+
{
740+
var contextFactory = await InitializeAsync<Context35111>();
741+
using var context = contextFactory.CreateContext();
742+
743+
var data = async
744+
? await context.Set<FooBar35111>().ToListAsync()
745+
: context.Set<FooBar35111>().ToList();
746+
}
747+
748+
protected class Context35111(DbContextOptions options) : DbContext(options)
749+
{
750+
public int Foo { get; set; }
751+
public long? Bar { get; set; }
752+
public List<long> Baz { get; set; }
753+
754+
protected override void OnModelCreating(ModelBuilder modelBuilder)
755+
{
756+
modelBuilder.Entity<FooBar35111>()
757+
.HasQueryFilter(e =>
758+
Foo == 1
759+
? Baz.Contains(e.Bar)
760+
: e.Bar == Bar);
761+
}
762+
}
763+
764+
public class FooBar35111
765+
{
766+
public long Id { get; set; }
767+
public long Bar { get; set; }
768+
}
769+
770+
#endregion
733771
}

0 commit comments

Comments
 (0)