dotnet / dotnet/efcore

AutoInclude causes ExecuteUpdate/Delete to have useless JOIN

Open
#29,992 9 comments 2 reactions 0 assignees View on GitHub
area-bulkupdate
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

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):

```c#
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 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(
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; }
}
```

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.