RIA 服务定制类

发布于 2024-08-05 00:49:54 字数 437 浏览 1 评论 0原文

使用 Silverlight 3 和 RIA 服务,我在 Web 项目中定义了以下类:

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 生成的类。

Using Silverlight 3 and RIA Services I have the following class defined in my Web project:

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

On the client, however, the class only shows up with the Name property. States doesn't show up anywhere. I'm assuming that I must be missing some sort of metadata but I don't know what it is.

Edit: I should clarify that State is a LinqToSql generated class.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

渡你暖光 2024-08-12 00:49:54

请参阅: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; }
    }
}        

祝你好运。

Please see: RIA Services Overview - 4.8.1 Returning Related Entities.

In service function where you return RegionCurrentStates list add DataLoadOptions and in metadata description add Include attribute to States propriety.

Add DataLoadOption in your query function defined in domain class.

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

    return this.Context.RegionCurrentStates;
}

In metadata:

//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; }
    }
}        

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文