JoeCool
JoeCool

Reputation: 4432

.Net RIA Services: Multiple loads to one callback

I have found that it's quite often the case I have multiple queries/entities that I want to load in RIA Services that are all related, and a single callback that processes the data once the loads have all been completed. However, I don't see a clean, easy way to do this with RIA Services without adding my own boilerplate code to either count callbacks (as in if I have three loads, then in the callback have a class variable that increments and returns if still < 3), or by chaining the loads, which wastes time since the load calls could be concurrent.

I'm starting to think my best option is to make a separate, reusable little class called "LoadGroup" that takes in multiple load queries and a callback function, and only invokes the callback once all the loads have completed. My question is: am I re-inventing the wheel here? Is there functionality of RIA Services that already basically does this (or a design pattern better than the one I'm suggesting)? Or should I go ahead with my plan of writing my own little class?

Thanks,

-Robert

Upvotes: 2

Views: 417

Answers (1)

Keith Adler
Keith Adler

Reputation: 21178

There is no chaining mechanism so your option to setup a master handler is the normal route. One other way to pull this off would be to simply expose a Model through Invoke which encapsulates all of the calls into a single result so that three calls to:

IQueryable<SomeType1> GetSomeType1()
{
}

IQueryable<SomeType2> GetSomeType2()
{
}

IQueryable<SomeType2> GetSomeType2()
{
}

Can be returned as (mock class)

public class SomeModel()
{
   public List<SomeType1> FirstCall()
   public List<SomeType2> SecondCall()
   public List<SomeType3> ThirdCall()
}

Exposed as an Invoke:

[Invoke]
    public SomeModel GetMultiple( IQueryable<SomeType1> first, IQueryable<SomeType2> second, IQueryable<SomeType3> third )

Upvotes: 1

Related Questions