代码之家  ›  专栏  ›  技术社区  ›  Johan Danforth

通过riadomainservice调用方法返回关联成员

  •  3
  • Johan Danforth  · 技术社区  · 14 年前

    [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; }
    }
    

    感谢您的帮助,我正在努力摸索DomainService/RIA的东西,我几乎要放弃了,转而使用“普通”WCF/REST:)

    1 回复  |  直到 14 年前
        1
  •  2
  •   Johan Danforth    14 年前