views:

249

answers:

4

Ok, I poked around before posting and can't seem to find anything... so here we go.

I decided that returning datasets, working with datasets and datatables in a front end app is a rather bad idea. So with the magic of generics I am returning a generic list via Webservice call ( not WCF just plain ol' asmx ) . That works dandy as long as you need to return one list per call to your webservice.

The scenario I am running into is that I have a more involved screen where there are a few dropdowns and so on. I need to bind those dropdowns to a generic list. Problem is that I don't want to make several web calls, one for each dropdown, to get my data. In the past I would have just returned a dataset and bound a dropdown to a specific table in the dataset.

So, it would be super to return multiple generic lists in one web call.

Things I've tried:

  1. Using a List of Lists
  2. Using a Collection of generic Lists
  3. Creating a base class and using a Collection of List<Base> , there are conversion issues there when trying to stuff objects into that List<Base>.
  4. Creating a class that has properties that return List<MyOneObject> , List<MySecondObject> .. etc. That works but it's kinda messy... I have lots of classes and screens in the app where this would happen. I could create a class like this that has a properties of List for each class, but like I said I think that may get out of control.

So at this point I have two options, #4 in the above list, or just return a dataset which I would prefer not to do :0) Has anyone run into this before ?

+3  A: 

Well I don't think returning multiple lists is a good idea, but if you are going to do it, I would create a wrapper class with each list exposed as a property in that class.

Something like

class Wrapper
{
   public List<object1> Object1List {get;set;}
   public List<object1> Object2List {get;set;}

}
Kevin
+1 - This is just a "Model" object in the Model/View/Controller pattern.
Eric Petroelje
I was not aware of that. You learn something new every day.
Kevin
I wound up using a Wrapper like that. That was option #4 on my list above. It ends up working out nicely. If one of those properties, say Object2List is left null the XML isn't even generated to pass back to the client. ( yes I know I'm being an efficiency Nazi). The other option was to serialize and compress to string and deserialize on the client... but that sounds like too much work. Anywho, thanks for the answer/confirmation :0)
kroolk
A: 

The answer is #4, via a class, either that or multiple calls, which you would rather not do

Stuart
A: 

Well it seems that I start all my answers today with a question? Why wouldn't you wanna do multiple calls behind the scene?

If you use one async call på dropdown/control you need to bind you'd get a more fluent user experience. (especially true for large independant lists) simply because if you only do one call all dropdown/conrtols will need to wait for all the other contrls data to be returned.

That being said: If the lists you're returning a close to each other in length youd could use a dictionary, using key to represent "property name" and the value to well represent the value. Very little code require and converting what ever the source is to a dictionary with .ToDictionary() is pretty straight forward (if the source is not IEnumerable implementing .ToDictionary() for that source is usually straight forward)

Rune FS
A: 

How do we bind now to different combo boxes ?

ozuinus