我有错误:“错误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”的表中。
没有行modelBuilder.Entity<UserPassword>().ToTable("User");
的代码有效,但我得到两个不同的表。