[Bug] EF Core InvalidOperationException on split query with FromSql join and collection Include

Abierto
#39,843 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
csharp, sql
Área
database

Línea de trabajo

Start from the provided EF Core query and reproduce the InvalidOperationException in a test or small console sample using EF Core 10.0.10. Trace the relational query translation for FromSql, Join, Include, and AsSplitQuery() through the relational query components. The work is done when the split query no longer throws for the collection include and returns the expected entities with ORDetails loaded.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

customer-reported
Bug description
Bug Summary

An unhandled System.InvalidOperationException occurs in Entity Framework Core when querying OR with OR.ORDetails included (AsSplitQuery()) via a FromSql join on @orIds.

Steps to Reproduce / Context
  • FE Screen / User Action: [Insert FE screen or action that triggers this request]
  • API Endpoint: [Insert endpoint, e.g., POST /api/...]
  • Request Payload / Parameters: [Insert sample payload, e.g., orIds, ClientId, WarehouseId]
Query Causing the Error
DbSet<JoinKey<long>>().FromSql(SELECT [Id] FROM @orIds, @p)
    .Join(
        inner: DbSet<OR>()
            .IgnoreQueryFilters(), 
        outerKeySelector: e => e.Id, 
        innerKeySelector: e => e.ORId, 
        resultSelector: (_, e) => e)
    .Where(e => (int?)e.ClientId == @_tenantInfo_ClientId)
    .Where(e => (int?)e.WarehouseId == @_tenantInfo_WarehouseId)
    .Include(x => x.ORDetails)
    .AsSplitQuery()

### Your code

```csharp
DbSet<JoinKey<long>>().FromSql(SELECT [Id] FROM @orIds, @p)
    .Join(
        inner: DbSet<OR>()
            .IgnoreQueryFilters(), 
        outerKeySelector: e => e.Id, 
        innerKeySelector: e => e.ORId, 
        resultSelector: (_, e) => e)
    .Where(e => (int?)e.ClientId == @_tenantInfo_ClientId)
    .Where(e => (int?)e.WarehouseId == @_tenantInfo_WarehouseId)
    .Include(x => x.ORDetails)
    .AsSplitQuery()
Stack traces
Microsoft.EntityFrameworkCore.Query: Debug: Including navigation: 'OR.ORDetails'.
Exception thrown: 'System.InvalidOperationException' in Microsoft.EntityFrameworkCore.Relational.dll
'Unable to translate a collection subquery in a projection since either parent or the subquery doesn't project necessary information required to uniquely identify it and correctly generate results on the client side. This can happen when trying to correlate on keyless entity type. This can also happen for some cases of projection before 'Distinct' or some shapes of grouping key in case of 'GroupBy'. These should either contain all key properties of the entity that the operation is applied on, or ...'
The thread '.NET TP Worker' (83024) has exited with code 0 (0x0).
Verbose output

EF Core version

10.0.10

Database provider

No response

Target framework

NET 10

Operating system

No response

IDE

No response

Lenguaje dominante
C#
Estrellas
14.8k
Forks
3.5k
Merge medio
2 d 22 h
PR fusionados (30 d)
158

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotnet/efcore

Todos los issues de dotnet/efcore

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.