You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading from EF Core 6 to EF Core 8, I've noticed that a particular query construct now throws an InvalidOperationException due to the LINQ expression not be able to be translated.
an InvalidOperationException is thrown with the following stacktrace:
System.InvalidOperationException
The LINQ expression 'DbSet<Foo>()
.Where(f => __bs_0
.Contains(MaterializeCollectionNavigation(
Navigation: Foo.Bars,
subquery: DbSet<Bar>()
.Where(b => EF.Property<long?>(f, "FooId") != null && object.Equals(
objA: (object)EF.Property<long?>(f, "FooId"),
objB: (object)EF.Property<long?>(b, "FooId"))))
.First().BarId))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.Translate(Expression expression)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.<ExecuteAsync>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken)
at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at UnitTests.SampleTests.FooBarTest() in C:\Repos\SampleTests\FooBarTests.cs:line 1095
at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 264
--- End of stack trace from previous location ---
at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48
at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90
The exception is thrown using both the In Memory and SQL Server LINQ providers and seems to be related to the use of the First operator in the Contains parameter. Can someone help me understand what's going on?
Thanks!
The text was updated successfully, but these errors were encountered:
After upgrading from EF Core 6 to EF Core 8, I've noticed that a particular query construct now throws an
InvalidOperationException
due to the LINQ expression not be able to be translated.Given the following entities:
when I run the following query:
an
InvalidOperationException
is thrown with the following stacktrace:The exception is thrown using both the In Memory and SQL Server LINQ providers and seems to be related to the use of the
First
operator in theContains
parameter. Can someone help me understand what's going on?Thanks!
The text was updated successfully, but these errors were encountered: