dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.77k stars 3.18k forks source link

Tags go missing when using final GroupBy #33794

Closed martsve closed 1 month ago

martsve commented 5 months ago

When performing a GroupBy any tags you have previously added to the IQueryable will disappear.

var query = _context.MyTable
    .TagWith("MissingTag")
    .GroupBy(x => x.AnyField);

var sql = query.ToQueryString()

Assert.Contains("MissingTag", sql);

EF Core version:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
cincuranet commented 5 months ago

I'm unable to reproduce the behavior you're describing. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

cincuranet commented 5 months ago

I'm closing because of inactivity. Will open when required information is provided.

springy76 commented 1 month ago

I see this too using 8.0.8, when the GroupBy is terminal.. no matter if executing against SQLite or NPGSQL (PostgreSQL)

roji commented 1 month ago

Minimal repro (with 9.0.0-rc.1) below. This is probably an oversight in the final GroupBy shaper (which is a special shaper).

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

// Tags not emitted
_ = await context.Blogs.TagWith("foo").GroupBy(b => b.Name).ToListAsync();

// Tags are emitted
_ = await context.Blogs.TagWith("foo").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();
}

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