我有以下实体:
public class Application
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public override int Id { get; set; }
public ApplicationSubcontractors ApplicationSubcontractors{get; set;}
}
public class ApplicationSubcontractors
{
public ApplicationId {get; set;}
public Application Application {get; set;}
}
我想对此进行映射,以便
Application
有ApplicationSubcontractors
且ApplicationSubcontractors
有Application
:
我如何将这一对比模型化?
Application实体是否存在Id主键这一事实?
答案 0 :(得分:1)
您可以执行以下操作:
public class Application
{
public int Id { get; set; }
public virtual ApplicationSubcontractor ApplicationSubcontractor { get; set; }
}
public class ApplicationSubcontractor
{
[Key, ForeignKey("Application")]
public override int Id { get; set; }
public virtual Application Application { get; set; }
}