开发者

A pattern for multiple LoadOperations using WCF RIA Services

开发者 https://www.devze.com 2023-01-02 10:36 出处:网络
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 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) =>
          开发者_StackOverflow社区  {
                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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消