Skip to content

AutoInclude causes ExecuteUpdate/Delete to have useless JOIN #29992

@roji

Description

@roji

With 8.0.0-alpha.1.23055.2, having an AutoInclude navigation on the target entity type causes ExecuteDelete to fail. Note that ExecuteUpdate does work correctly, and having an owned entity type also works (see related #28727):

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

ctx.Blogs.ExecuteUpdate(s => s.SetProperty(b => b.Name, "Foo"));

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>(
            x => x.Navigation(b => b.Details).AutoInclude());
    }
}

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

    public BlogDetails Details { get; set; }
}

public class BlogDetails
{
    public int Id { get; set; }
    public int Foo { get; set; }
}

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions