-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
GroupBy over complex types #33491
Labels
area-groupby
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-enhancement
Milestone
Comments
Note that we also don't translate GroupBy over an owned entity (#29018); doing that doesn't seem useful since entity identity semantics apply, and so the group can always only contain one item. Minimal reproawait using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
_ = await context.Blogs
.GroupBy(b => b.Address)
.Select(g => new { g.Key, Count = g.Count() })
.ToListAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> 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();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// modelBuilder.Entity<Blog>().OwnsOne(b => b.Address);
modelBuilder.Entity<Blog>().ComplexProperty(b => b.Address);
}
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
} |
roji
added a commit
to roji/efcore
that referenced
this issue
Apr 9, 2024
roji
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Apr 9, 2024
roji
added a commit
to roji/efcore
that referenced
this issue
Apr 9, 2024
roji
added a commit
that referenced
this issue
Apr 9, 2024
roji
changed the title
A complex property(own type) is not included in the group by
Cannot do GroupBy over a complex type
Apr 9, 2024
roji
changed the title
Cannot do GroupBy over a complex type
GroupBy over complex types
Sep 23, 2024
This was referenced Sep 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-groupby
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-enhancement
Include your code
SimpleRepo1.zip
When I try to group by a property that has a complexProperty, this complexProperty is not involved in the final sql query. (there were no similar problems in ef 6 )
Generated sql query (Ef6 made similar requests via distinct)
if you use Сount(), the error is the same
Include stack traces
Include provider and version information
EF Core version: 8.0.3
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 8.0)
Operating system:
IDE: (e.g. Visual Studio 2022 17.9.2)
The text was updated successfully, but these errors were encountered: