3

我得到这个方法的DomainService我最SL的ViewModel使用Invoke属性调用:通过利雅的DomainService调用返回相关成员方法

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

在我的视图模型的代码如下所示:

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和作者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; } 
} 

现在,代码工作正常,excep t关联的作者没有被转移到客户端/视图模型,Recipy的Author属性为空。我认为使用[Associate]和[Include]属性会有诀窍吗?

感谢您的帮助,我努力地神交的DomainService/RIA的东西,我很接近放弃走“正常” WCF/REST,而不是:)

回答

2

据我了解,[ Invoke]目前不支持复杂的层次结构,所以我通过确保对集合上的[Include]和[Association]具有正确的属性来解决此问题,并返回使用正常的RIA查询方法。

相关问题