使用 WCF RIA 服务的多个 LoadOperations 模式

发布于 2024-09-04 20:21:04 字数 1043 浏览 2 评论 0原文

我希望能够在一次调用中加载多个 RIA 实体集,而无需将多个小型 LoadOperations 链接/嵌套在一起,以便它们按顺序加载。

我有几个页面,上面有许多组合框。这些组合框填充有数据库中的静态值(例如状态值)。

现在,我通过一种方法将这些值预加载到我的虚拟机中,该方法将我想要加载的每种类型的一系列 LoadOperations 串在一起。例如:

public void LoadEnums() {
        context.Load(context.GetMyStatusValues1Query()).Completed += (s, e) =>
        {
            this.StatusValues1 = context.StatusValues1;
            context.Load(context.GetMyStatusValues2()).Completed += (s1, e1) =>
            {
                this.StatusValues2 = context.StatusValues2;
                context.Load(context.GetMyStatusValues3Query()).Completed += (s2, e2) =>
                {
                    this.StatusValues3 = context.StatusValues3;

                     (....and so on)


                };
            };
        };
};

虽然这工作正常,但看起来有点令人讨厌。另外,我想知道最后一个加载操作何时完成,以便我可以在此之后加载我想要处理的任何实体,以便这些枚举值在组合框和列表框等表单元素中正确解析。 (我认为)如果不创建委托并在完成最后一个加载操作时调用它,我就无法轻松地做到这一点。

所以我的问题是:是否有人知道更好的使用模式,理想情况下我可以在单个 LoadOperation 中加载所有静态实体集?

I would like to be able to load several RIA entitysets in a single call without chaining/nesting several small LoadOperations together so that they load sequentially.

I have several pages that have a number of comboboxes on them. These comboboxes are populated with static values from a database (for example status values).

Right now I preload these values in my VM by one method that strings together a series of LoadOperations for each type that I want to load. For example:

public void LoadEnums() {
        context.Load(context.GetMyStatusValues1Query()).Completed += (s, e) =>
        {
            this.StatusValues1 = context.StatusValues1;
            context.Load(context.GetMyStatusValues2()).Completed += (s1, e1) =>
            {
                this.StatusValues2 = context.StatusValues2;
                context.Load(context.GetMyStatusValues3Query()).Completed += (s2, e2) =>
                {
                    this.StatusValues3 = context.StatusValues3;

                     (....and so on)


                };
            };
        };
};

While this works fine, it seems a bit nasty. Also, I would like to know when the last loadoperation completes so that I can load whatever entity I want to work on after this, so that these enumerated values resolve properly in form elements like comboboxes and listboxes. (I think) I can't do this easily above without creating a delegate and calling that on the completion of the last loadoperation.

So my question is: does anyone out there know a better pattern to use, ideally where I can load all my static entitysets in a single LoadOperation?

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

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

发布评论

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

评论(1

玻璃人 2024-09-11 20:21:04

看起来答案很简单,至少在 RIA 服务 1.0 中是这样:

只需依次调用 LoadOperations,域上下文就会按照调用顺序使它们同步。

即,

context.Load(context.GetMyStatusValues1Query()).Completed += (s, e) =>
  {
    this.StatusValues1 = context.StatusValues1;
  }

context.Load(context.GetMyStatusValues2Query()).Completed += (s1, e1) =>
  {
    this.StatusValues1 = context.StatusValues2;
  }

这对我来说似乎并不明显,因为我希望在第一个查询之后立即调用第二个查询,并且当它仍在加载时,并抛出“LoadOperation in Progress”异常。

这很好,因为这意味着在我的问题示例中使用丑陋的嵌套 LoadOperation 模式的唯一原因是第二个 LoadOperation 取决于第一个 LoadOperation 的结果。

It seems that the answer is quite simple, at least in RIA services 1.0:

Just invoke the LoadOperations one after another and the Domain Context will make them synchronously in the order they are invoked.

i.e.

context.Load(context.GetMyStatusValues1Query()).Completed += (s, e) =>
  {
    this.StatusValues1 = context.StatusValues1;
  }

context.Load(context.GetMyStatusValues2Query()).Completed += (s1, e1) =>
  {
    this.StatusValues1 = context.StatusValues2;
  }

That doesn't seem obvious to me because I would have expected the second query to be invoked immediately after the first and while it was still loading, and throwing the "LoadOperation in progress" exception.

This is great though because it means the only reason to use the ugly nested LoadOperation pattern in the example in my question is when the second LoadOperation depends on the result of the first.

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