Closed wendt88 closed 7 years ago
nice suggestion, actually all logic that performs mapping from IDataReader to dictionaries/models already exists in DbDataAdapter.SelectQuery
(some reorganization to avoid copy-paste is needed of course).
I've checked the code and I think it is better to introduce some generic component for mapping data from any IDataReader
to list of dictionaries or models. Since we already have RecordSetReader
it can be used to achieve desired result:
RecordSet rs;
var myModels = new RecordSetReader(rs).Query().ToList<ModelType>();
Query
might be an extension method for IDataReader
that returns some generic QueryResult
that has methods that currently exist in DbDataAdapter.SelectQuery
(ToDictionaryList, ToList etc).
Additional motivation for this approach is #35 - this might be elegant solution for reading multiple resultsets.
Of course some refactoring is needed to reorganize existing SelectQuery code.
Added DataReaderResult
class that implements all mapping methods that exist in DbDataAdapter.SelectQuery
(ToList, ToSingle, ToDictionary, ToRecordSet etc).
Now it is possible to map RecordSet data to model in the following way:
RecordSet rs;
var myModels = new DataReaderResult( new RecordSetReader(rs) ).ToList<ModelType>();
Released in 1.0.2
Hi, i think it would be a nice feature to add some methods to the RecordSet: