使用单个密钥在EF中生成关系

本文关键字:关系 EF 单个 密钥 | 更新日期: 2023-09-27 18:11:04

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

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; }
}

我想从配置文件类到其他类使用一个1对1的关系,只是配置文件Id作为外部,而不是所有相关类的Id。我该如何使用流利的Api??我还需要有简历=>需要一个个人资料…我怎么能这样做,或者这是可能的吗?

使用单个密钥在EF中生成关系

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