通过Ria DomainService Invoke方法返回关联成员

时间:2010-09-05 19:28:19

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

我使用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 and 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; }
}

现在,代码工作正常,除了关联的Author没有转移到client / viewmodel,Recipy的Author属性为null。我认为使用[Associate]和[Include]属性可以解决问题吗?

感谢您提供任何帮助,我正在努力寻找DomainService / RIA的东西,我接近放弃并转而“正常”WCF / REST:)

1 个答案:

答案 0 :(得分:2)

据我所知,[Invoke]目前不支持复杂的层次结构,所以我通过确保集合上的[Include]和[Association]具有正确的属性来解决它,并回到使用而是一种正常的RIA查询方法。