2009-09-18 60 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