C# EF core 2.0,在TPH模型类中拥有一个
当我尝试在EF Core 2.0中迁移我的模型时,我遇到了问题C# EF core 2.0,在TPH模型类中拥有一个,c#,asp.net,.net,entity-framework,C#,Asp.net,.net,Entity Framework,当我尝试在EF Core 2.0中迁移我的模型时,我遇到了问题 public class Profile { [Key] public Guid Id { get; set; } public Guid UserId { get; set; } public ExternalUser User { get; set; } } public class OrganizationCustomerProfile : Profile { public stri
public class Profile
{
[Key]
public Guid Id { get; set; }
public Guid UserId { get; set; }
public ExternalUser User { get; set; }
}
public class OrganizationCustomerProfile : Profile
{
public string CompanyName { get; set; }
public Address LegalAddress { get; set; }
public Address ActualAddress { get; set; }
public BusinessRequisites Requisites { get; set; }
public string President { get; set; }
public IEnumerable<ContactPerson> ContactPerson { get; set; }
}
public class PersonCustomerProfile : Profile
{
public FullName Person { get; set; }
public Address Address { get; set; }
public string PhoneNumber { get; set; }
}
public class ContactPerson
{
[Key]
public Guid Id { get; set; }
public FullName Person { get; set; }
public string Rank { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public Guid ProfileId { get; set; }
public Profile Profile { get; set; }
}
我用于TPH绑定的代码:
public DbSet<Profile> UserProfiles { get; set; }
public DbSet<ContactPerson> ContactPerson { get; set; }
public DbSet<OrganizationCustomerProfile> OrganizationCustomerProfile { get; set; }
public DbSet UserProfiles{get;set;}
公共数据库集联系人{get;set;}
公共数据库集组织CustomerProfile{get;set;}
modelBuilder.Entity().HasKey(u=>u.Id);
modelBuilder.Entity().OwnsOne(e=>e.ActualAddress);
modelBuilder.Entity().OwnsOne(e=>e.LegalAddress);
modelBuilder.Entity().OwnsOne(e=>e.Requisites);
但当我尝试进行迁移时,会出现一个错误:
“无法对实体类型使用表'UserProfiles'
“OrganizationCustomerProfile.ActualAddress#Address”,因为它具有
与派生实体类型“OrganizationCustomerProfile”的关系。
将关系指向基类型“Profile”或映射
“OrganizationCustomerProfile.ActualAddress#Address”指向其他地址
桌子。”
那么,这个错误的原因是什么呢?是否无法在EF Core 2.0中创建层次结构继承
谢谢大家! 目前似乎不支持这一点:
@Dmitry我认为TPT也不受支持“目前,EF Core中只实现了每层次表(TPH)模式。其他常见模式如每类型表(TPT)和每具体类型表(TPC)尚不可用。”-
public DbSet<Profile> UserProfiles { get; set; }
public DbSet<ContactPerson> ContactPerson { get; set; }
public DbSet<OrganizationCustomerProfile> OrganizationCustomerProfile { get; set; }
modelBuilder.Entity<Profile>().HasKey(u => u.Id);
modelBuilder.Entity<OrganizationCustomerProfile>().OwnsOne(e => e.ActualAddress);
modelBuilder.Entity<OrganizationCustomerProfile>().OwnsOne(e => e.LegalAddress);
modelBuilder.Entity<OrganizationCustomerProfile>().OwnsOne(e => e.Requisites);