Best pattern to load enumerated values from DAL using WCF RIA Services

Posted by Dale Halliwell on Stack Overflow See other posts from Stack Overflow or by Dale Halliwell
Published on 2010-06-08T00:55:40Z Indexed on 2010/06/13 22:32 UTC
Read the original article Hit count: 361

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight