Ef Core 8: table splitting

I’m trying to use table splitting with EF Core 8 and I’m having some issues with the mappings. Here’s what my types look like:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class Employee
{
public int Id{ get; set; }
public int Version{get; set}
public string Name{ get; set; }
// other properties
}
public class EmployeeSummary
{
public int Id{ get; set; }
public string Name{ get; set; }
public Employee Emnployee { get;set;}
}
</code>
<code>public class Employee { public int Id{ get; set; } public int Version{get; set} public string Name{ get; set; } // other properties } public class EmployeeSummary { public int Id{ get; set; } public string Name{ get; set; } public Employee Emnployee { get;set;} } </code>
public class Employee
{

    public int Id{ get; set; }

    public int Version{get; set}

    public string Name{ get; set; }

    // other properties
}

public class EmployeeSummary
{

    public int Id{ get; set; }

    public string Name{ get; set; }

    public Employee Emnployee { get;set;}
}

And here are the mappings:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public sealed class EmployeeTypeConfiguration: IEntityTypeConfiguration<Employee>
{
public void Configure(EntityTypeBuilder<Employee> builder)
{
builder.ToTable("Employees");
builder.HasKey(f => f.Id);
builder.Property(f => f.Id).HasColumnName("EmpId");
builder.Property(f => f.Version).IsConcurrencyToken( );
builder.Property(f => f.Name).HasColumnName("Name");
// other mappings
}
}
public sealed class EmployeeSummaryTypeConfiguration: IEntityTypeConfiguration<EmployeeSummary>
{
public void Configure(EntityTypeBuilder<EmployeeSummary> builder)
{
builder.ToTable("Employees");
builder.HasKey(f => f.Id);
builder.Property(f => f.Id).HasColumnName("EmpId");
builder.Property<int>("Version").IsConcurrencyToken( );
builder.Property(e => e.Name).HasColumnName("Name");
builder.HasOne(f => f.Employee)
.WithOne( )
.HasForeignKey<Employee>(f1 => f1.Id);
builder.Navigation(f => f.Employee).IsRequired( );
}
}
</code>
<code>public sealed class EmployeeTypeConfiguration: IEntityTypeConfiguration<Employee> { public void Configure(EntityTypeBuilder<Employee> builder) { builder.ToTable("Employees"); builder.HasKey(f => f.Id); builder.Property(f => f.Id).HasColumnName("EmpId"); builder.Property(f => f.Version).IsConcurrencyToken( ); builder.Property(f => f.Name).HasColumnName("Name"); // other mappings } } public sealed class EmployeeSummaryTypeConfiguration: IEntityTypeConfiguration<EmployeeSummary> { public void Configure(EntityTypeBuilder<EmployeeSummary> builder) { builder.ToTable("Employees"); builder.HasKey(f => f.Id); builder.Property(f => f.Id).HasColumnName("EmpId"); builder.Property<int>("Version").IsConcurrencyToken( ); builder.Property(e => e.Name).HasColumnName("Name"); builder.HasOne(f => f.Employee) .WithOne( ) .HasForeignKey<Employee>(f1 => f1.Id); builder.Navigation(f => f.Employee).IsRequired( ); } } </code>
public sealed class EmployeeTypeConfiguration: IEntityTypeConfiguration<Employee> 
{
    
    public void Configure(EntityTypeBuilder<Employee> builder) 
    {
        builder.ToTable("Employees");
        
        builder.HasKey(f => f.Id);
        builder.Property(f => f.Id).HasColumnName("EmpId");
        
        builder.Property(f => f.Version).IsConcurrencyToken( );

        builder.Property(f => f.Name).HasColumnName("Name");

       // other mappings
   }
}


public sealed class EmployeeSummaryTypeConfiguration: IEntityTypeConfiguration<EmployeeSummary> 
{
    public void Configure(EntityTypeBuilder<EmployeeSummary> builder) 
    {
        builder.ToTable("Employees");
        
        builder.HasKey(f => f.Id);
        builder.Property(f => f.Id).HasColumnName("EmpId");
        
        builder.Property<int>("Version").IsConcurrencyToken( );
        
        builder.Property(e => e.Name).HasColumnName("Name");

        builder.HasOne(f => f.Employee)
               .WithOne( )
               .HasForeignKey<Employee>(f1 => f1.Id);
        builder.Navigation(f => f.Employee).IsRequired( );

    }
}

After adding EmployeeSummary, I’m no longer able to insert a new Employee:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Employee emp = new("123123123");
employee.UpdateWorkPlace(newWorkplace);
// more code
dbContext.Set<Employee>().Add(emp)
await dbContext.SaveChangesAsync(); // throws exception
</code>
<code>Employee emp = new("123123123"); employee.UpdateWorkPlace(newWorkplace); // more code dbContext.Set<Employee>().Add(emp) await dbContext.SaveChangesAsync(); // throws exception </code>
Employee emp = new("123123123");
employee.UpdateWorkPlace(newWorkplace);
// more code
dbContext.Set<Employee>().Add(emp)
await dbContext.SaveChangesAsync();  // throws exception

When I run the previous snippet, I’ll end up with the following error:

System.InvalidOperationException
The value of ‘Employee.Id’ is unknown when attempting to save changes. This is because the property is also part of a foreign key for which the principal entity in the relationship is not known.

What am I doing wrong?

Thanks.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật