2012-12-27 79 views
0

我一直試圖解決這個整個下午,但已經空了。我們的模式看起來不太正確,但我沒有權力去改變它。實體框架代碼第一個實體分裂沒有虛擬導航屬性?

基本上我需要這3個表結合起來:

dbo.Charity 
    Id (PK, int, not null) 
    Name (varchar(100), not null) 

dbo.CharityCountry 
    CharityId (PK, FK, int, not null) 
    CountryId (PK, FK, int, not null) 

dbo.Country 
    Id (PK, int, not null) 
    Name (varchar(100), not null) 

,並讓他們到EF模型:

但我心亂如麻,因爲許多文章似乎離開了如何做到這一點用映射類:

public class CharityMap : EntityTypeConfiguration<Charity> 
{ 
    public CharityMap() 
    { 
     this.HasKey(t => t.Id); 

     this.ToTable("dbo.Charity"); 

     this.Property(t => t.Id).HasColumnName("Id"); 
     this.Property(t => t.Name).HasColumnName("Name"); 
     ... 
    } 
} 

我需要知道什麼是投入了......,我不知道如何映射一個複合實體關聯,其中外鍵不存在FR om主要實體。

的慈善對象是這樣的:

public class Charity 
{ 
    public int? Id { get; set; } 
    public string Name { get; set; } 
    public Country Country { get; set; } 
} 

和國家目標:

public class Country 
{  
    public int? Id { get; set; } 
    public string Name { get; set; } 
} 

回答