【发布时间】: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