2011-03-24 73 views
0

我有一個entityA包含entityB的EntityCollection。 我更新了metdata爲EntityA與[包括]裝修過定義entityB線路如下:從另一個實體獲取EntityCollection

[Include] 
public EntityCollection<daily> daily { get; set; } 
在我的DomainService類

我有一個函數來檢索entityA如下:

var summary = 
(from S in ObjectContext.summery.Include("daily") 
       where S.daily_number == daily_number 
       && S.month_number == month_number 
       && S.period_id == period_id 
       select S).FirstOrDefault(); 
      return summary; 

從客戶端,我總是得到entityB的Zero數。 我在這裏錯過了什麼!

問候

回答

0

你需要與AssociationAttribute定義summerydaily之間的關聯。

[Include] 
[Association("SomeUniqueName", "summery_id", "parent_summery_id", IsForeignKey = false)] 
public EntityCollection<daily> daily { get; set; } 

我提出如下假設你的類

public class summery 
{ 
... 
    public int? summery_id { get; set; } 
... 
} 

public class daily 
{ 
... 
    // Foreign key to the parent summery 
    public int parent_summery_id { get; set; } 
... 
} 

編輯:

針對瓦利德的評論,複合外鍵關聯可能看起來像

[Association("SomeUniqueName", 
      "summery_field1, summary_field2, summary_field3", 
      "parent_summary_filed1, parent_summary_filed2, parent_summary_filed3", 
      IsForeignKey = false)] 
+0

你好,如果該協會要求比以上更多的話e鍵,例如summery_field1,summary_field2,summary_field3與parent_summary_filed1,parent_summary_filed2,parent_summary_filed3 ?? – Waleed 2011-03-29 12:13:57

相關問題