0

我對EF和RIA很陌生,所以我不確定這是否應該起作用。如何通過RIA服務獲得實體及其子實體

我這裏顯示一個簡單的模型:

alt text

我加入了POCO templates for entity framework,一切是有線作爲它sohould我可以延遲加載,更改的通知和相關Fixup時......(我真的希望你仍然在閱讀)

問題是,雖然在服務器上我可以通過簡單地調用comp.SubComponents加載組件的子組件。但是,由於某種原因,我沒有在客戶端的功能...我的ComponentRIAServices.web.g.cs(生成的代碼)沒有列表SubComponent

這是如何工作的?我應該在RIA服務上有這個功能嗎?

public IEnumerable<SubComponent> GetSubComponents(int componentId) 
{ 
    return m_ctx.SubComponents 
      .Where(x => x.Component.Id == componentId) 
      .OrderBy(x => x.Name); 
} 

回答

0

在我的元數據我是缺少的屬性在我及部件的元數據子屬性[Include][Association]。這個類有看起來像這樣:

[MetadataType(typeof(Component.Metadata))] 
public partial class Component 
{ 
    internal sealed class Metadata 
    { 
     [Key] 
     public int Id { get; set; } 

     [Include] 
     [Association("ComponentSubComponent","Id", "ComponentId")] 
     public ICollection<SubComponent> SubComponents { get; set; } 

    } 
} 

我希望它可以幫助別人:)

額外提示:我在加入[Include]屬性,因爲我並沒有引用正確的裝配問題。確保你添加引用System.ServiceModel.DomainServices.Server.dll

編輯:我忘了提,我也缺少在子實體

alt text

1

我不知道很多關於RIA服務,但我懷疑懶加載可以從客戶端的工作......我認爲你需要加載SubComponents熱切當你加載Components,你給他們前到客戶端:

public IEnumerable<Component> GetComponents() 
{ 
    return m_ctx.Components.Include("SubComponents") 
      .OrderBy(x => x.Name); 
} 
+0

我已經試過了ComponentId財產,但事情是我身邊組件沒有SubComponents屬性:(因此我無法訪問組件的SubComponent ...我可以手動加載SubComponents並從上下文(客戶端上下文)獲取它們, – sebagomez 2010-11-06 11:36:28