Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos query projection on owned entity list throws InvalidOperationException variable 'jArray1Object' of type 'Newtonsoft.Json.Linq.JObject' referenced from scope #31974

Closed
JoasE opened this issue Oct 5, 2023 · 3 comments

Comments

@JoasE
Copy link

JoasE commented Oct 5, 2023

File a bug

I get an InvalidOperationException when I try to do a projection on an owned entity in a list of owned entities using the cosmos db provider.

Include your code

https://github.com/JoasE/EfOwnedTypeProjection

var persons = await context.Persons.AsNoTracking().Select(x => new
{
    x.Id,
    x.Name,
    Addresses = x.Homes.Select(x => x.Address).ToArray(),
}).ToArrayAsync();
modelBuilder.UsePropertyAccessMode(PropertyAccessMode.PreferFieldDuringConstruction);

modelBuilder.Entity<Person>(p =>
{
    p.Property(x => x.Id).ValueGeneratedNever().ToJsonProperty("id");
    p.HasKey(x => x.Id);
    p.Property(x => x.Name);
    p.OwnsMany(x => x.Homes, h =>
    {
        h.Property(x => x.Id).ValueGeneratedNever();
        h.OwnsOne(x => x.Address, a =>
        {
            a.Property(x => x.Value);
        });
    });
    p.HasPartitionKey(x => x.Id);
});

Include stack traces

System.InvalidOperationException: 'variable 'jArray1Object' of type 'Newtonsoft.Json.Linq.JObject' referenced from scope '', but it is not defined'
   at System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitBlock(BlockExpression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitConditional(ConditionalExpression node)
   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression`1 node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.NewExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
   at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)
   at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosShapedQueryCompilingExpressionVisitor.VisitShapedQuery(ShapedQueryExpression shapedQueryExpression)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression)
   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>d__67`1.MoveNext()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToArrayAsync>d__68`1.MoveNext()
   at Program.<<Main>$>d__0.MoveNext() in C:\Users\joase\source\repos\EfOwnedTypeProjection\EfOwnedTypeProjection\Program.cs:line 10

Include provider and version information

EF Core version: 8.0.0-rc.1.23419.6
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Target framework: .NET 8.0 (8.0.0-rc.1.23420.5)
Operating system: Windows 11
IDE: Visual Studio 2022 Version 17.8.0 Preview 2.0

@ajcvickers
Copy link
Member

Note for triage: not a regression and still fails on the latest daily build.

@ajcvickers
Copy link
Member

/cc @AndriySvyryd

@AndriySvyryd
Copy link
Member

Duplicate of #16926

@AndriySvyryd AndriySvyryd marked this as a duplicate of #16926 Oct 11, 2023
@AndriySvyryd AndriySvyryd closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@AndriySvyryd AndriySvyryd removed this from the Backlog milestone Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants