or How I refactored my seemingly identical methods with generic type parameters
As I've written in the past I'm using BLToolkit lightweight ORM on one of my projects. But some parts of it seem very silly actually and I can't really see why did they decide to do certain parts the way that they did. One of them being the configuration for multiple result sets. You know those where you write TSQL query that returns more than one result. BLToolkit has this nice DbManager mapping method called ExecuteResultSet() that takes an array of MapResultSet objects. And these you have to prepare yourself first so mapper will actually populate your object lists. Their example looks like this (just the relevant code):
1: List<Parent> parents = new List<Parent>();
2: MapResultSet[] sets = new MapResultSet[3];
3:
4: sets[0] = new MapResultSet(typeof(Parent), parents);
5: sets[1] = new MapResultSet(typeof(Child));
6: sets[2] = new MapResultSet(typeof(Grandchild));
7: // and so on and so forth for each result set
8:
9: using (DbManager db = new DbManager())
10: {
11: db
12: .SetCommand(TestQuery)
13: .ExecuteResultSet(sets);
14: }
As you can see you have to create an array of MapResultSet objects of the correct size (using a magic value - and you know I don't like them) and then set an instance to each (again using magic values). Seems tedious? I thought so as well. Hence I've done it differently.