【问题标题】:Returning Associated Members via Ria DomainService Invoke Method通过 Ria DomainService Invoke 方法返回关联成员
【发布时间】:2011-04-08 12:38:36
【问题描述】:

我使用 Invoke 属性从我的 SL ViewModel 调用了这个 DomainService 方法:

[Invoke]
public ServiceModel.Recipy GetRecipyById(int recipyId)
{
    return new Recipy
                {
                    RecipyId = 1,
                    Name = "test",
                    Description = "desc",
                    Author = new Author
                                {
                                    AuthorId = 1,
                                    Name = "Johan"
                                }
                };
}

我的 ViewModel 中的代码如下所示:

public RecipyViewModel()
{
    context.GetRecipyById(1, RecipyLoadedCallback, null);
}

private void RecipyLoadedCallback(InvokeOperation<Recipy> obj)
{
    _name = obj.Value.Name;
    _description = obj.Value.Description;
    _authorName = obj.Value.Author.Name;
}

Recipy 和 Author POCO/ServiceModel 类:

public class Recipy
{
    [Key]
    public int RecipyId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }

    [Association("Author", "RecipyId", "AuthorId")]
    [Include]
    public Author Author { get; set; }
}

public class Author
{
    [Key]
    public int AuthorId { get; set; }
    public string Name { get; set; }
}

现在,代码工作正常,除了关联的作者没有转移到客户端/视图模型,Recipy 的作者属性为空。我认为使用 [Associate] 和 [Include] 属性可以解决问题?

感谢您的帮助,我正在努力了解 DomainService/RIA 的东西,我快要放弃了,转而使用“正常”的 WCF/REST :)

【问题讨论】:

    标签: silverlight-3.0 silverlight-4.0 rich-internet-application domainservices


    【解决方案1】:

    据我了解,[Invoke] 目前不支持复杂的层次结构,因此我通过确保我在集合中具有正确的 [Include] 和 [Association] 属性来解决它,然后重新使用而是使用普通的 RIA 查询方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多