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

Explicitly selecting properties from JSON OwnedCollection crashes on OrderBy #33360

Closed
magahl opened this issue Mar 20, 2024 · 2 comments
Closed

Comments

@magahl
Copy link

magahl commented Mar 20, 2024

Im not ceratin if this is supported or not. I have created a sample repo that can be found here: https://github.com/magahl/EFCore.Json.Failure

When i explicitly select properties from a json structure property i get an exception from EFCOre saying

Query

var persons = await context.Persons.AsNoTracking().Select(x => new Person
{
    FirstName = x.FirstName,
    Id = x.Id,
    Addresses = x.Addresses.Select(a => new Address
    {
        Street = a.Street,
        Zip = a.Zip
    }).ToList()
}).ToListAsync();

Generated query

      SELECT [a].[Street], [a].[Zip], [p].[Id]
      FROM [Persons] AS [p]
      CROSS APPLY OPENJSON([p].[Addresses], '$') WITH (
          [Street] nvarchar(max) '$.Street',
          [Zip] nvarchar(max) '$.Zip'
      ) AS [a]
      ORDER BY [p].[Id], CAST([a].[key] AS int)

Where the last cast in the order by is the problem.

StackTrace

Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'key'.
   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.<PopulateSplitCollectionAsync>g__InitializeReaderAsync|31_0[TCollection,TElement,TRelatedEntity](RelationalQueryContext queryContext, RelationalCommandCache relationalCommandCache, IReadOnlyList`1 readerColumns, Boolean detailedErrorsEnabled, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.PopulateSplitCollectionAsync[TCollection,TElement,TRelatedEntity](Int32 collectionId, RelationalQueryContext queryContext, IExecutionStrategy executionStrategy, RelationalCommandCache relationalCommandCache, IReadOnlyList`1 readerColumns, Boolean detailedErrorsEnabled, SplitQueryResultCoordinator resultCoordinator, Func`3 childIdentifier, IReadOnlyList`1 identifierValueComparers, Func`5 innerShaper, Func`4 relatedDataLoaders)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.TaskAwaiter(Func`1[] taskFactories)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in C:\Code\ConsoleApp2\ConsoleApp2\Program.cs:line 11
   at Program.<Main>(String[] args)
ClientConnectionId:95d86444-d773-451e-a85f-cd002cda857a
Error Number:207,State:1,Class:16

Logs

C:/Code/ConsoleApp2/ConsoleApp2/bin/Debug/net8.0/ConsoleApp2.exe 
warn: 2024-03-20 12:03:32.460 CoreEventId.SensitiveDataLoggingEnabledWarning[10400] (Microsoft.EntityFrameworkCore.Infrastructure) 
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
dbug: 2024-03-20 12:03:32.481 CoreEventId.ShadowPropertyCreated[10600] (Microsoft.EntityFrameworkCore.Model.Validation) 
      The property 'Address.PersonId' was created in shadow state because there are no eligible CLR members with a matching name.
dbug: 2024-03-20 12:03:32.481 CoreEventId.ShadowPropertyCreated[10600] (Microsoft.EntityFrameworkCore.Model.Validation) 
      The property 'Address.Id' was created in shadow state because there are no eligible CLR members with a matching name.
dbug: 2024-03-20 12:03:32.602 CoreEventId.ContextInitialized[10403] (Microsoft.EntityFrameworkCore.Infrastructure) 
      Entity Framework Core 8.0.3 initialized 'TestContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:8.0.3' with options: SensitiveDataLoggingEnabled QuerySplittingBehavior=SplitQuery using lazy loading proxies 
dbug: 2024-03-20 12:03:32.652 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      Context 'TestContext' started tracking 'Person' entity with key '{Id: deb26a60-986b-4dfd-9d79-c75bc812bd23}'.
dbug: 2024-03-20 12:03:32.663 CoreEventId.ValueGenerated[10808] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      'TestContext' generated temporary value '-2147482647' for the property 'Address.Id'.
dbug: 2024-03-20 12:03:32.680 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      Context 'TestContext' started tracking 'Address' entity with key '{PersonId: deb26a60-986b-4dfd-9d79-c75bc812bd23, Id: -2147482647}'.
dbug: 2024-03-20 12:03:32.681 CoreEventId.ValueGenerated[10808] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      'TestContext' generated temporary value '-2147482646' for the property 'Address.Id'.
dbug: 2024-03-20 12:03:32.681 CoreEventId.StartedTracking[10806] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      Context 'TestContext' started tracking 'Address' entity with key '{PersonId: deb26a60-986b-4dfd-9d79-c75bc812bd23, Id: -2147482646}'.
dbug: 2024-03-20 12:03:32.685 CoreEventId.SaveChangesStarting[10004] (Microsoft.EntityFrameworkCore.Update) 
      SaveChanges starting for 'TestContext'.
dbug: 2024-03-20 12:03:32.687 CoreEventId.DetectChangesStarting[10800] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      DetectChanges starting for 'TestContext'.
dbug: 2024-03-20 12:03:32.692 CoreEventId.DetectChangesCompleted[10801] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      DetectChanges completed for 'TestContext'.
dbug: 2024-03-20 12:03:32.740 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      The foreign key property 'Address.Id' was detected as changed from '-2147482647' to '1' for entity with key '{PersonId: deb26a60-986b-4dfd-9d79-c75bc812bd23, Id: 1}'.
dbug: 2024-03-20 12:03:32.761 CoreEventId.ForeignKeyChangeDetected[10803] (Microsoft.EntityFrameworkCore.ChangeTracking)
      The foreign key property 'Address.Id' was detected as changed from '-2147482646' to '2' for entity with key '{PersonId: deb26a60-986b-4dfd-9d79-c75bc812bd23, Id: 2}'.
dbug: 2024-03-20 12:03:32.772 RelationalEventId.ConnectionCreating[20005] (Microsoft.EntityFrameworkCore.Database.Connection) 
      Creating DbConnection.
dbug: 2024-03-20 12:03:32.817 RelationalEventId.ConnectionCreated[20006] (Microsoft.EntityFrameworkCore.Database.Connection) 
      Created DbConnection. (43ms).
dbug: 2024-03-20 12:03:32.819 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.086 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection) 
      Opened connection to database 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.091 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
      Creating DbCommand for 'ExecuteReader'.
dbug: 2024-03-20 12:03:33.095 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
      Created DbCommand for 'ExecuteReader' (2ms).
dbug: 2024-03-20 12:03:33.101 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
      Initialized DbCommand for 'ExecuteReader' (10ms).
dbug: 2024-03-20 12:03:33.106 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
      Executing DbCommand [Parameters=[@p0='[{"Street":"Street","Zip":"55555"},{"Street":"Street","Zip":"44444"}]' (Nullable = false) (Size = 69), @p1='deb26a60-986b-4dfd-9d79-c75bc812bd23', @p2='Magnus' (Nullable = false) (Size = 4000)], CommandType='Text', CommandTimeout='30']
      SET IMPLICIT_TRANSACTIONS OFF;
      SET NOCOUNT ON;
      INSERT INTO [Persons] ([Addresses], [Id], [FirstName])
      VALUES (@p0, @p1, @p2);
info: 2024-03-20 12:03:33.156 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command) 
      Executed DbCommand (50ms) [Parameters=[@p0='[{"Street":"Street","Zip":"55555"},{"Street":"Street","Zip":"44444"}]' (Nullable = false) (Size = 69), @p1='deb26a60-986b-4dfd-9d79-c75bc812bd23', @p2='Magnus' (Nullable = false) (Size = 4000)], CommandType='Text', CommandTimeout='30']
      SET IMPLICIT_TRANSACTIONS OFF;
      SET NOCOUNT ON;
      INSERT INTO [Persons] ([Addresses], [Id], [FirstName])
      VALUES (@p0, @p1, @p2);
dbug: 2024-03-20 12:03:33.159 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command)
      Closing data reader to 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.164 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
      A data reader for 'Json.Failure' on server '(local)' is being disposed after spending 6ms reading results.
dbug: 2024-03-20 12:03:33.167 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closing connection to database 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.171 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closed connection to database 'Json.Failure' on server '(local)' (3ms).
dbug: 2024-03-20 12:03:33.176 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking) 
      The 'Person' entity with key '{Id: deb26a60-986b-4dfd-9d79-c75bc812bd23}' tracked by 'TestContext' changed state from 'Added' to 'Unchanged'.
dbug: 2024-03-20 12:03:33.176 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
      The 'Address' entity with key '{PersonId: deb26a60-986b-4dfd-9d79-c75bc812bd23, Id: 1}' tracked by 'TestContext' changed state from 'Added' to 'Unchanged'.
dbug: 2024-03-20 12:03:33.177 CoreEventId.StateChanged[10807] (Microsoft.EntityFrameworkCore.ChangeTracking)
      The 'Address' entity with key '{PersonId: deb26a60-986b-4dfd-9d79-c75bc812bd23, Id: 2}' tracked by 'TestContext' changed state from 'Added' to 'Unchanged'.
dbug: 2024-03-20 12:03:33.178 CoreEventId.SaveChangesCompleted[10005] (Microsoft.EntityFrameworkCore.Update)
      SaveChanges completed for 'TestContext' with 1 entities written to the database.
dbug: 2024-03-20 12:03:33.213 CoreEventId.QueryCompilationStarting[10111] (Microsoft.EntityFrameworkCore.Query) 
      Compiling query expression:
      'DbSet<Person>()
          .AsNoTracking()
          .Select(x => new Person{
              FirstName = x.FirstName,
              Id = x.Id,
              Addresses = x.Addresses
                  .Select(a => new Address{
                      Street = a.Street,
                      Zip = a.Zip
                  }
                  )
                  .ToList()
          }
          )'
dbug: 2024-03-20 12:03:33.369 CoreEventId.QueryExecutionPlanned[10107] (Microsoft.EntityFrameworkCore.Query) 
      Generated query execution expression:
      'queryContext => new SplitQueryingEnumerable<Person>(
          (RelationalQueryContext)queryContext,
          RelationalCommandCache.QueryExpression(
              Client Projections:
                  0 -> 0
                  1 -> 1
              SELECT p.FirstName, p.Id
              FROM Persons AS p
              ORDER BY p.Id ASC),
          null,
          Func<QueryContext, DbDataReader, ResultContext, SplitQueryResultCoordinator, Person>,
          null,
          Func<QueryContext, IExecutionStrategy, SplitQueryResultCoordinator, Task>,
          ConsoleApp2.TestContext,
          False,
          False,
          True
      )'
dbug: 2024-03-20 12:03:33.383 RelationalEventId.ConnectionOpening[20000] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opening connection to database 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.384 RelationalEventId.ConnectionOpened[20001] (Microsoft.EntityFrameworkCore.Database.Connection)
      Opened connection to database 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.384 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command)
      Creating DbCommand for 'ExecuteReader'.
dbug: 2024-03-20 12:03:33.384 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
      Created DbCommand for 'ExecuteReader' (0ms).
dbug: 2024-03-20 12:03:33.385 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
      Initialized DbCommand for 'ExecuteReader' (0ms).
dbug: 2024-03-20 12:03:33.385 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
      Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [p].[FirstName], [p].[Id]
      FROM [Persons] AS [p]
      ORDER BY [p].[Id]
info: 2024-03-20 12:03:33.391 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
      Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [p].[FirstName], [p].[Id]
      FROM [Persons] AS [p]
      ORDER BY [p].[Id]
dbug: 2024-03-20 12:03:33.412 RelationalEventId.CommandCreating[20103] (Microsoft.EntityFrameworkCore.Database.Command) 
      Creating DbCommand for 'ExecuteReader'.
dbug: 2024-03-20 12:03:33.412 RelationalEventId.CommandCreated[20104] (Microsoft.EntityFrameworkCore.Database.Command)
      Created DbCommand for 'ExecuteReader' (0ms).
dbug: 2024-03-20 12:03:33.412 RelationalEventId.CommandInitialized[20106] (Microsoft.EntityFrameworkCore.Database.Command)
      Initialized DbCommand for 'ExecuteReader' (0ms).
dbug: 2024-03-20 12:03:33.412 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
      Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [a].[Street], [a].[Zip], [p].[Id]
      FROM [Persons] AS [p]
      CROSS APPLY OPENJSON([p].[Addresses], '$') WITH (
          [Street] nvarchar(max) '$.Street',
          [Zip] nvarchar(max) '$.Zip'
      ) AS [a]
      ORDER BY [p].[Id], CAST([a].[key] AS int)
fail: 2024-03-20 12:03:33.418 RelationalEventId.CommandError[20102] (Microsoft.EntityFrameworkCore.Database.Command)
      Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT [a].[Street], [a].[Zip], [p].[Id]
      FROM [Persons] AS [p]
      CROSS APPLY OPENJSON([p].[Addresses], '$') WITH (
          [Street] nvarchar(max) '$.Street',
          [Zip] nvarchar(max) '$.Zip'
      ) AS [a]
      ORDER BY [p].[Id], CAST([a].[key] AS int)
fail: 2024-03-20 12:03:33.437 CoreEventId.QueryIterationFailed[10100] (Microsoft.EntityFrameworkCore.Query) 
      An exception occurred while iterating over the results of a query for context type 'ConsoleApp2.TestContext'.
      Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'key'.
         at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)
         at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
      --- End of stack trace from previous location ---
         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.<PopulateSplitCollectionAsync>g__InitializeReaderAsync|31_0[TCollection,TElement,TRelatedEntity](RelationalQueryContext queryContext, RelationalCommandCache relationalCommandCache, IReadOnlyList`1 readerColumns, Boolean detailedErrorsEnabled, CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)      
         at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.PopulateSplitCollectionAsync[TCollection,TElement,TRelatedEntity](Int32 collectionId, Relatio
nalQueryContext queryContext, IExecutionStrategy executionStrategy, RelationalCommandCache relationalCommandCache, IReadOnlyList`1 readerColumns, Boolean detailedErrorsEnabled, SplitQueryResultCoordinator resultCoordinator, Func`3 childIdentifier, IReadOnlyList`1 identifierValueComparers, Func`5 innerShaper, Func`4 relatedDataLoaders)
         at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.TaskAwaiter(Func`1[] taskFactories)
         at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
      ClientConnectionId:95d86444-d773-451e-a85f-cd002cda857a
      Error Number:207,State:1,Class:16
dbug: 2024-03-20 12:03:33.439 RelationalEventId.DataReaderClosing[20301] (Microsoft.EntityFrameworkCore.Database.Command) 
      Closing data reader to 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.441 RelationalEventId.DataReaderDisposing[20300] (Microsoft.EntityFrameworkCore.Database.Command)
      A data reader for 'Json.Failure' on server '(local)' is being disposed after spending 49ms reading results.
dbug: 2024-03-20 12:03:33.441 RelationalEventId.ConnectionClosing[20002] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closing connection to database 'Json.Failure' on server '(local)'.
dbug: 2024-03-20 12:03:33.441 RelationalEventId.ConnectionClosed[20003] (Microsoft.EntityFrameworkCore.Database.Connection)
      Closed connection to database 'Json.Failure' on server '(local)' (0ms).
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'key'.
   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__211_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.<PopulateSplitCollectionAsync>g__InitializeReaderAsync|31_0[TCollection,TElement,TRelatedEntity](RelationalQueryContext queryContext, RelationalCommandCache relationalCommandCache, IReadOnlyList`1 readerColumns, Boolean detailedErrorsEnabled, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.PopulateSplitCollectionAsync[TCollection,TElement,TRelatedEntity](Int32 collectionId, RelationalQue
ryContext queryContext, IExecutionStrategy executionStrategy, RelationalCommandCache relationalCommandCache, IReadOnlyList`1 readerColumns, Boolean detailedErrorsEnabled, SplitQueryResultCoordinator resultCoordinator, Func`3 childIdentifier, IReadOnlyList`1 identifierValueComparers, Func`5 innerShaper, Func`4 relatedDataLoaders)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.TaskAwaiter(Func`1[] taskFactories)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in C:\Code\ConsoleApp2\ConsoleApp2\Program.cs:line 11
   at Program.<Main>(String[] args)
ClientConnectionId:95d86444-d773-451e-a85f-cd002cda857a
Error Number:207,State:1,Class:16

EF Core version: 8.0.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: net8
Operating system: Windows
IDE: Rider

@maumar
Copy link
Contributor

maumar commented Apr 12, 2024

I confirmed this fails on 8.0.3 but works on 8.0.4
This is the sql we generate now:

SELECT JSON_VALUE([a].[value], '$.Street') AS [Street], JSON_VALUE([a].[value], '$.Zip') AS [Zip], [p].[Id]
FROM [Persons] AS [p]
CROSS APPLY OPENJSON([p].[Addresses], '$') AS [a]
ORDER BY [p].[Id], CAST([a].[key] AS int)

@magahl you can just update your project to latest patch and problem should go away, closing

@maumar maumar closed this as completed Apr 12, 2024
@maumar
Copy link
Contributor

maumar commented Apr 12, 2024

likely a dupe of #32976

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
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

4 participants