请参阅:RIA 服务概述- 4.8.1 返回相关实体。
在返回 RegionCurrentStates 列表的服务函数中,添加 DataLoadOptions 并在元数据描述中将 Include 属性添加到 States 属性。
在域类中定义的查询函数中添加 DataLoadOption。
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; }
}
}
祝你好运。