【发布时间】:2020-01-26 11:47:24
【问题描述】:
我正在通过 asp.net core 实现一个项目。在 sql server 中,我有一个名为申请人的表,它有两个子 LegalApplicant 和 PersonApplicant 都继承自申请人表,并且每个都有相关的属性。每个 LegalApplicant 和 PersonApplicant 表都与申请人表具有一对一的关系。我使用 DB first 方法在 Visual Studio 中为它们搭建脚手架。现在我想用linq定义它们之间的关系。如果有人可以解决我的问题,我将不胜感激。我是 EF 核心的新手。甚至我在理解语法方面也有问题。
public partial class PersonApplicant:Applicant
{
public int ApplicantId { get; set; }
public int ApplicantType { get; set; }
public string Username { get; set; }
public string NationalCode { get; set; }
public string BirthCertificateNo { get; set; }
public string IssuePlace { get; set; }
public virtual Applicant Applicant { get; set; }
public virtual EntityType ApplicantTypeNavigation { get; set; }
}
public partial class LegalApplicant : Applicant
{
public int ApplicantId { get; set; }
public int ApplicantType { get; set; }
public string EconomicCode { get; set; }
public string RegisterNo { get; set; }
public string NationalCode { get; set; }
public virtual Applicant Applicant { get; set; }
public virtual EntityType ApplicantTypeNavigation { get; set; }
}
public partial class Applicant
{
public Applicant()
{
Apiapplicant = new HashSet<Apiapplicant>();
LegalApplicant = new HashSet<LegalApplicant>();
PersonApplicant = new HashSet<PersonApplicant>();
}
public int ApplicantId { get; set; }
public int ApplicantType { get; set; }
public string Address { get; set; }
public string Description { get; set; }
public string IsDeleted { get; set; }
public string Name { get; set; }
public virtual EntityType ApplicantTypeNavigation { get; set; }
public virtual ICollection<Apiapplicant> Apiapplicant { get; set; }
public virtual ICollection<LegalApplicant> LegalApplicant { get; set; }
public virtual ICollection<PersonApplicant> PersonApplicant { get; set; }
}
【问题讨论】:
-
在这里写下你的代码。
-
我使用 DB first 方法在 Visual Studio 中为它们搭建脚手架。嗯,这也应该定义了关系。
标签: linq asp.net-core inheritance ef-core-3.1