dotnet / dotnet/efcore

EntitySplittingMissingPropertiesMainFragment does not take owned navigations/complex properties into account

Open
#36,171 0 comments 1 reaction 1 assignee Claimed by @AndriySvyryd View on GitHub
area-model-building
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

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

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

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(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

Addresses { get; set; }
}

public class Address
{
public string Street { 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.