我从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"
}
};
}
我的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; }
}
现在,该代码可以正常工作,除了未将关联的Author转移到客户端/ View 模型之外,Recipy的Author属性为null。我以为使用[Associate]和[Include]属性可以解决问题?
感谢您提供的任何帮助,我正努力尝试使用DomainService / RIA的功能,而我即将放弃并改用“常规” WCF / REST :)
最佳答案
据我了解,[Invoke]目前不支持复杂的层次结构,因此我通过确保我对集合中的[Include]和[Association]具有正确的属性来解决了该问题,并返回使用常规RIA查询方法代替。