简体   繁体   English

使用WCF RIA服务进行多个LoadOperation的模式

[英]A pattern for multiple LoadOperations using WCF RIA Services

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. 我希望能够在单个调用中加载多个RIA实体集,而无需将多个小的LoadOperation链接/嵌套在一起,以便它们依次加载。

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. 现在,我通过一种方法将这些值预加载到VM中,该方法将要加载的每种类型的一系列LoadOperations串在一起。 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. (我认为)如果没有创建委托并在最后一次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? 所以我的问题是:有没有人知道更好的使用模式,理想情况下,我可以在一个LoadOperation中加载所有静态实体集?

It seems that the answer is quite simple, at least in RIA services 1.0: 似乎答案很简单,至少在RIA服务1.0中:

Just invoke the LoadOperations one after another and the Domain Context will make them synchronously in the order they are invoked. 只是一个接一个地调用LoadOperations,域上下文将使它们按照被调用的顺序同步。

ie

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. 在我看来,这似乎并不明显,因为我希望第二个查询在第一个查询仍在加载后立即被调用,并引发“ LoadOperation in progress”异常。

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. 尽管这很不错,但是因为这意味着在我的问题示例中使用丑陋的嵌套LoadOperation模式的唯一原因是何时第二个LoadOperation依赖于第一个的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM