2009-09-18 43 views
1

使用Silverlight 3和RIA服務我在我的Web項目中定義了以下類:RIA服務定製類

public class RegionCurrentStates 
{ 
    public RegionCurrentStates() 
    { 
     Name = String.Empty; 
     States= new List<State>(); 
    } 
    [Key] 
    public string Name { get; set; } 
    public List<State> States{ get; set; } 
} 

在客戶端,然而,類只顯示了Name屬性。國家不會出現在任何地方。我假設我必須缺少某種元數據,但我不知道它是什麼。

編輯:我應該說明State是一個LinqToSql生成的類。

回答

2

請參閱:RIA Services Overview - 4.8.1返回相關實體。

在您返回RegionCurrentStates列表的服務函數中添加DataLoadOptions並在元數據描述中添加Include屬性以適合States。

將數據加載選項添加到您在域類中定義的查詢函數中。

public IQueryable<RegionCurrentStates> GetRegionCurrentStates() 
{ 
    DataLoadOptions loadOpts = new DataLoadOptions(); 
    loadOpts.LoadWith<RegionCurrentStates>(r => r.States); 
    this.Context.LoadOptions = loadOpts; 

    return this.Context.RegionCurrentStates; 
} 

在元數據:

//This class in generated by RIA wizard when you create 
//your DomainService (based on LinqToSqlDomainService) and you check 
//[x]Generate metadata class in wizard window 
//file: MyService.metadata.cs 

[MetadataTypeAttribute(typeof(RegionCurrentStates.RegionCurrentStatesMetadata))] 
public partial class RegionCurrentStates 
{ 
    internal sealed class RegionCurrentStatesMetadata 
    {  
     [Include] //Add (only) this line 
     public List<State> States{ get; set; } 
    } 
}   

好運。

+0

我強烈建議看看'RIA Service Overview'文檔。這是在您使用RIA時必須閱讀的內容。 – rlodina 2009-11-17 09:08:16

+0

是的,我同意。我最終也找到了答案。 – Nate 2009-11-17 17:15:48

+0

這個文件是否仍然存在?鏈接沒有帶我到任何地方。 – 2010-04-05 17:47:43