-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Copy link
Labels
Milestone
Description
When defining a complex property on a derived TPH entity type, its columns are non-nullable, making it impossible to insert other types in the hierarchy.
Repro
await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
ctx.Set<Blog>().Add(new Blog());
await ctx.SaveChangesAsync();
public class BlogContext : DbContext
{
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>();
modelBuilder.Entity<SpecialBlog>().ComplexProperty(s => s.ComplexThing);
}
}
public class Blog
{
public int Id { get; set; }
public string? Name { get; set; }
}
public class SpecialBlog : Blog
{
public int RegularColumn { get; set; }
public ComplexThing ComplexThing { get; set; }
}
public class ComplexThing
{
public int Foo { get; set; }
}