4

I haven't found a way to retrieve two lists of objects from an SP with two select statements. Is it possible with BLToolkit, or can only hierarchical data be fetched in such a manner?

I'm trying to replace a dataset containing two unrelated tables.

Carl R
  • 8,104
  • 5
  • 48
  • 80

1 Answers1

4

It turns out it was really simple. :)

Here's how you return multiple unrelated resultsets using BLToolkit.

List<Apple> apples = new List<Apple>();
List<Orange> oranges = new List<Orange>();

MapResultSet[] sets = new MapResultSet[2];
sets[0] = new MapResultSet(typeof(Apple), apples);
sets[1] = new MapResultSet(typeof(Orange), oranges); //Make sure both lists are added

//Skip adding relations

using (DbManager db = new DbManager())
{
    db
        .SetSpCommand("usp_Fruit_GetBySomething",
            db.Parameter("someParam", someParam))
        .ExecuteResultSet(sets);
}

foreach(Apple apple in apples)
{
  profit(apple);
}

foreach(Orange orange in oranges)
{
  profit(orange);
}
Carl R
  • 8,104
  • 5
  • 48
  • 80
  • Is your tables related in any way? I have a similar scenario and plan to pull multiple results from several tables, which hold flattened xml. If they are related, how are you doing updates. – scope_creep Jun 29 '11 at 12:58
  • @scope_creep In this case, the tables weren't related at all. – Carl R Jun 29 '11 at 20:19
  • @scope_creep I'm doing updates using stored procedures one object at time, looping if necessary. – Carl R Jun 29 '11 at 20:21
  • Thanks, Carl R That was the way I was thinking of doing it, which is good to know that i'm vaguely on the right track. – scope_creep Jul 04 '11 at 13:24