Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public class ExpressionTreeFuncletizer : ExpressionVisitor
private static readonly bool UseOldBehavior35152 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35152", out var enabled35152) && enabled35152;

private static readonly bool UseOldBehavior35111 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35111", out var enabled35111) && enabled35111;

private static readonly MethodInfo ReadOnlyCollectionIndexerGetter = typeof(ReadOnlyCollection<Expression>).GetProperties()
.Single(p => p.GetIndexParameters() is { Length: 1 } indexParameters && indexParameters[0].ParameterType == typeof(int)).GetMethod!;

Expand Down Expand Up @@ -552,7 +555,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 = UseOldBehavior35111 ? test : ProcessEvaluatableRoot(test, ref testState);
}

if (ifTrueState.IsEvaluatable)
{
ifTrue = ProcessEvaluatableRoot(ifTrue, ref ifTrueState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Context35111>();
using var context = contextFactory.CreateContext();

var data = async
? await context.Set<FooBar35111>().ToListAsync()
: context.Set<FooBar35111>().ToList();
}

protected class Context35111(DbContextOptions options) : DbContext(options)
{
public int Foo { get; set; }
public long? Bar { get; set; }
public List<long> Baz { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<FooBar35111>()
.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
}