3

我使用 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 :)

4

1 回答 1

2

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

于 2010-09-24T14:39:25.883 回答