dotnet / dotnet/efcore

Query: improve identifier validation so that we don't throw exception for "insufficient identifiers" when there is only one collection in the projection

Open
#33,485 1 comment 0 reactions 0 assignees View on GitHub
area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Example scenario:

```cs
await using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();

await context.Blogs.Select(b => new
{
b.Id,
Names = new[] { b.Name }.Concat(b.Posts.Select(c => c.Title)).ToList()
}).ToListAsync();

public class BlogContext : DbContext
{
public DbSet Blogs { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}

public class Blog
{
public int Id { get; set; }
public string Name { get; set; }

public List Posts { get; set; }
}

public class Post
{
public int Id { get; set; }
public string Title { get; set; }

public Blog Blog { get; set; }
}
```

This throws ` 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.`

In theory we should be ok here because there is no second collection in the projection, so we should know how to bucket the results only based on identifiers of the parent (Blogs).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.