nreco / data

Fast DB-independent DAL for .NET Core: abstract queries, SQL commands builder, schema-less data access, POCO mapping (micro-ORM).
https://www.nrecosite.com/dalc_net.aspx
MIT License
184 stars 39 forks source link

Extend RecordSet #37

Closed wendt88 closed 7 years ago

wendt88 commented 7 years ago

Hi, i think it would be a nice feature to add some methods to the RecordSet:

ToList<T>()
ToDictionaryList()
Single<T>()
VitaliyMF commented 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).

VitaliyMF commented 7 years ago

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.

VitaliyMF commented 7 years ago

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>();
VitaliyMF commented 7 years ago

Released in 1.0.2