使用单个键在 EF 中生成关系

Generating relationship in EF using single Key

我想像这样映射我的实体之间的关系:

public partial class Profile  {
    [Key]
    public int ProfileId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string MiddleName { get; set; }
    public string Gender { get; set; }
    public string DateOfBirth { get; set; }
    public int Age { get; set; }
    public string CivilStatus { get; set; }
    public string Email { get; set; }
    public string Telephone { get; set; }
    public string Mobile { get; set; }
    public string City { get; set; }
    public string District { get; set; }
    public string Province { get; set; }
    public string Region { get; set; }
    public int Zip { get; set; }


    public virtual Application Application { get; set; }
    public virtual Education Education { get; set; }
    public virtual Identification Identification { get; set; }
    public virtual Job Job { get; set; }
    public virtual Resume Resume { get; set; }
    }

public partial class Resume {
    public int ResumeId { get; set; }
    public int ProfileId { get; set; }
    public string ResumeFile { get; set; }

    public virtual Profile Profile { get; set; }
  }

public partial class Job
{


    public int JobId { get; set; }
    public int ProfileId { get; set; }
    public string PreviousCompany { get; set; }
    public string InclusiveDate { get; set; }
    public string Position { get; set; }

    public virtual Profile Profile { get; set; }
}

public partial class Education
{


    public int EducationId { get; set; }
    public int ProfileId { get; set; }
    public string School { get; set; }
    public string EducationLevel { get; set; }
    public string YearGraduated { get; set; }
    public string Degree { get; set; }

    public virtual Profile Profile { get; set; }
}

我想从配置文件 class 到其他 classes 建立一对一的关系,只使用配置文件 ID 作为外部而不是所有相关的 ID 类.我将如何使用流利的 Api 来做到这一点?我还需要有 Resume => 需要一份个人资料...我该怎么做或者有可能吗??。

如果您想将所有内容都映射到一个 table 中,您可以向每个 class 添加注释 [Table("Profile")] 并从中删除不同的 ID。这个操作叫做"Table spliting"我可以给你推荐这个视频: http://www.youtube.com/watch?v=l9QXArMPyHc&index=13&list=PL6n9fhu94yhUPBSX-E2aJCnCR3-_6zBZx 以提高您对问题的理解。