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查詢方法。

相關問題