Skip to content

AutoInclude causes ExecuteDelete to fail #30572

@roji

Description

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

ctx.Blogs
    .ExecuteDelete();

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; }
}

Split off from #29992

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions