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
I've recently started migrating an ASP.NET 3.1 Core project to target .NET 5. I now get an exception whenever I try to resolve a single entry from my DbContext:
Unhandled exception. System.InvalidOperationException: The LINQ expression 'ShapedQueryExpression:
QueryExpression:
Projection Mapping:
EmptyProjectionMember -> [EntityProjectionExpression]
SELECT 1
FROM MonthlyTarget AS m
ShaperExpression: EntityShaperExpression:
EntityType: MonthlyTarget
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.Where(namelessParameter{0} => new object[]
{
(object)EF.Property<int>(EntityShaperExpression:
EntityType: AnnualTarget
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
, "CommissionYear"),
(object)EF.Property<int>(EntityShaperExpression:
EntityType: AnnualTarget
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
, "ProductConsultantId")
} != null && new object[]
{
(object)EF.Property<int>(EntityShaperExpression:
EntityType: AnnualTarget
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
, "CommissionYear"),
(object)EF.Property<int>(EntityShaperExpression:
EntityType: AnnualTarget
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
, "ProductConsultantId")
} == new object[]
{
(object)EF.Property<int>(namelessParameter{0}, "CommissionYear"),
(object)EF.Property<int>(namelessParameter{0}, "ProductConsultantId")
})' 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.<VisitMethodCall>g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& )
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.TranslateSubquery(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitExtension(Expression extensionExpression)
at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Translate(SelectExpression selectExpression, Expression expression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.TranslateSubquery(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.IncludeExpression.VisitChildren(ExpressionVisitor visitor)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitExtension(Expression extensionExpression)
at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Translate(SelectExpression selectExpression, Expression expression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
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__DisplayClass9_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.Find(Object[] keyValues)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Find(Object[] keyValues)
at <Program>$.<Main>$(String[] args) in C:\Projects\Playground\Program.cs:line 18
Verbose Output
PS C:\Projects\Playground> dotnet ef dbcontext list --verbose
Using project 'C:\Projects\Playground\Playground.csproj'.
Using startup project 'C:\Projects\Playground\Playground.csproj'.
Writing 'C:\Projects\Playground\obj\Playground.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\me\AppData\Local\Temp\tmp6785.tmp /verbosity:quiet /nologo C:\Projects\Playground\Playground.csproj
Writing 'C:\Projects\Playground\obj\Playground.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\me\AppData\Local\Temp\tmp6A26.tmp /verbosity:quiet /nologo C:\Projects\Playground\Playground.csproj
Build started...
dotnet build C:\Projects\Playground\Playground.csproj /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.15
Build succeeded.
dotnet exec --depsfile C:\Projects\Playground\bin\Debug\net5.0\Playground.deps.json --additionalprobingpath C:\Users\me\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Projects\Playground\bin\Debug\net5.0\Playground.runtimeconfig.json C:\Users\me\.dotnet\tools\.store\dotnet-ef\5.0.0\dotnet-ef\5.0.0\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll dbcontext list --assembly C:\Projects\Playground\bin\Debug\net5.0\Playground.dll --startup-assembly C:\Projects\Playground\bin\Debug\net5.0\Playground.dll --project-dir C:\Projects\Playground\ --language C# --working-dir C:\Projects\Playground --verbose --root-namespace Playground
Using assembly 'Playground'.
Using startup assembly 'Playground'.
Using application base 'C:\Projects\Playground\bin\Debug\net5.0'.
Using working directory 'C:\Projects\Playground'.
Using root namespace 'Playground'.
Using project directory 'C:\Projects\Playground\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'Playground'...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'Context'.
Provider and Version Information
EF Core version: 5.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 5.0
Operating system: Windows 10 1909
IDE: Visual Studio 2019 16.8.1
The text was updated successfully, but these errors were encountered:
I've recently started migrating an ASP.NET 3.1 Core project to target .NET 5. I now get an exception whenever I try to resolve a single entry from my DbContext:
The stack trace for this is listed below. The only thing particularly special about this entity is that it has nested ownership of other entities:
ProductConsultant
owns manyAnnualTarget
AnnualTarget
owns manyMonthlyTarget
It seems to be this nested ownership that causes the issue. I've reproduced this as minimally as possible using the code below.
Steps To Reproduce
dotnet ef migrations add InitialCreate
, which should successfully generate a migrationdotnet ef database update
to apply the migrationdotnet run
, which should generate some output and terminate successfullydotnet ef database update 0
dotnet ef migrations remove
netcoreapp3.1
withnet5.0
InvalidOperationException
should get thrown this timeProject File
Program
Stack Trace
Verbose Output
Provider and Version Information
EF Core version: 5.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 5.0
Operating system: Windows 10 1909
IDE: Visual Studio 2019 16.8.1
The text was updated successfully, but these errors were encountered: