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,而不是:)