エラーが発生しました:「エラー 0114: リレーションシップ制約内の従属ロールとプリンシパル ロールのプロパティの数は、完全に同一である必要があります。」このコードで
public abstract class UserBase
{
[Key]
public Guid Guid { get; set; }
[Required]
public string Name { get; set; }
}
public class User : UserBase
{
public DateTime? BirthDate { get; set; }
public UserPassword Password { get; set; }
}
public class Outsourcer : UserBase
{
public Guid OutsourcingCompanyGuid { get; set; }
public OutsourcingCompany OutsourcingCompany { get; set; }
}
public class UserPassword
{
[Key]
public Guid UserGuid { get; set; }
public User User { get; set; }
public string Password { get; set; }
public string Salt { get; set; }
}
public class MyContext : DbContext
{
public DbSet<UserBase> Users { get; set; }
public DbSet<UserPassword> UserPasswords { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<UserBase>().ToTable("UserBase");
modelBuilder.Entity<Outsourcer>().ToTable("Outsourcer");
modelBuilder.Entity<User>().ToTable("User");
modelBuilder.Entity<User>().HasRequired(t => t.Password).WithRequiredPrincipal(t => t.User);
modelBuilder.Entity<UserPassword>().ToTable("User");
}
}
User と UserPassword を「User」という名前の 1 つのテーブルにマージします。行のないコードはmodelBuilder.Entity<UserPassword>().ToTable("User");
機能しますが、2 つの異なるテーブルが表示されます。