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

发布于 2024-09-17 11:40:03 字数 1486 浏览 8 评论 0原文

我使用 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; }
}

现在,代码工作正常,只是关联的 Author 不是传输到客户端/视图模型时,Recipy 的 Author 属性为 null。我认为使用 [Associate] 和 [Ininclude] 属性可以解决问题?

感谢您的帮助,我正在努力理解 DomainService/RIA 的东西,我几乎要放弃并转而使用“正常”WCF/REST :)

I got this DomainService method I'm calling from my SL ViewModel using the Invoke attribute:

[Invoke]
public ServiceModel.Recipy GetRecipyById(int recipyId)
{
    return new Recipy
                {
                    RecipyId = 1,
                    Name = "test",
                    Description = "desc",
                    Author = new Author
                                {
                                    AuthorId = 1,
                                    Name = "Johan"
                                }
                };
}

The code in my ViewModel looks like this:

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

The Recipy and Author POCO/ServiceModel classes:

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

Now, the code works fine, except that the associated Author is not transfered over to the client/viewmodel, the Author property of Recipy is null. I thought that using the [Associate] and [Include] attributes would do the trick?

Thanks for any help, I'm trying hard to grok the DomainService/RIA stuff and I'm close to giving up and go "normal" WCF/REST instead :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚人国度 2024-09-24 11:40:03

据我了解,[Invoke] 目前不支持复杂的层次结构,因此我通过确保集合上的 [Include] 和 [Association] 具有正确的属性来解决这个问题,然后返回使用普通的 RIA改为查询方法。

As I understand it, [Invoke] doesn't support complex hierarchies at the moment, so I solved it by making sure I had the correct attributes for [Include] and [Association] on the collection, and went back to using a normal RIA query method instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文