Skip to content

EntitySplittingMissingPropertiesMainFragment does not take owned navigations/complex properties into account #36171

Open

Description

@roji

We have a model validation check to make sure that the main table has at least one non-key property on it (EntitySplittingMissingPropertiesMainFragment). This only looks at regular properties, and does not take owned navigations/complex properties into account. When these are mapped to column(s) on the main table, the check should not throw.

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

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>(b =>
        {
            b.OwnsMany(p => p.Addresses, b => b.ToJson());
            b.SplitToTable("Phonenumbers", b => b.Property(p => p.Phonenumber));
        });
    }
}

public class Blog
{
    public int Id { get; set; }
    // public string Name { get; set; } // Without this model validation throws although Addresses is mapped
    public string Phonenumber { get; set; }

    public List<Address> Addresses { get; set; }
}

public class Address
{
    public string Street { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions