views:

492

answers:

1

Given a simple statement, such as:

<statement id="SelectProducts" resultMap="???">
  SELECT * FROM Products
</statement>

Is it possible to get a list of dictionary objects where the keys are the column names? ie.

var list = Mapper.QueryForList<IDictionary<string,string>>("SelectProducts", null);

IDictionary<string, string> dict = list[0];
// dict["id"] == "1"
// dict["name"] == "Some Product Name"
// dict["price"] == "$9.99"
// etc.

I'd like to generalize the result of a query to handle any number of columns/column names without mapping to specific properties on some class.

I realize the example here would fail since a result set may have duplicate (or null) column names. I've thought about a result class that holds an indexed list of key-value pairs. The key thing here is retaining the column information somewhere.

+1  A: 

You can do this by setting the class attribute to HashTable in the resultMap configuration. More details available here.

Ben Hoffstein