2015-09-04 40 views
0

我要地圖我的實體之間的關係是這樣的:生成關係單個鍵

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?我還需要Resume =>需要一個配置文件...我該怎麼做,或者有可能嗎?

+0

你想將每個類映射到單獨的表中,還是要將所有類映射到一個表中? – Andrey

+0

我想將他們映射到配置文件表..要像這樣profile.Job –

回答

1

如果你想映射一張表中的所有東西,你可以給每個類添加註釋[Table(「Profile」)],並從中刪除不同的ID。這個操作被稱爲「表分割」我可以推薦你這個視頻: http://www.youtube.com/watch?v=l9QXArMPyHc&index=13&list=PL6n9fhu94yhUPBSX-E2aJCnCR3-_6zBZx 以提高你對這個問題的理解。

+0

我一直在尋找。謝謝 –

+0

在視頻中討論了一個稍微不同的方法來做這個操作,但效果相同。 – Andrey

+0

是的..很棒。我甚至不知道Fluent API可以做到這一點。真的很棒的方法 –