DataReader
Converts a DbDataReader into an IEnumerable. It is the core of the library’s data extraction pipeline.
It exposes a single method, ToEnumerable, which is pre-compiled AOT using Linq.Expressions.
This class caches the database schema and reuses all library-level caches during extraction to produce the most efficient AOT compilation.
Extract as Entity Model
using (var connection = new SqlConnection(connectionString))
{
using (var reader = connection.ExecuteReader("SELECT * FROM [dbo].[Person];"))
{
var people = DataReader.ToEnumerable<Person>((DbDataReader) reader);
// Do the stuffs for 'people' here
}
}
Extract as Dynamic/ExpandoObject
using (var connection = new SqlConnection(connectionString))
{
using (var reader = connection.ExecuteReader("SELECT * FROM [dbo].[Person];"))
{
var people = DataReader.ToEnumerable((DbDataReader) reader);
// Do the stuffs for 'people' here
}
}
DbFields
Passing a list of DbField objects allows the compiler to skip unnecessary DB-NULL checks.
using (var connection = new SqlConnection(connectionString))
{
var dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get<Person>(), null);
using (var reader = connection.ExecuteReader("SELECT * FROM [dbo].[Person];"))
{
var people = DataReader.ToEnumerable<Person>((DbDataReader) reader,
dbFields,
connection.GetDbSetting());
// Do the stuffs for 'people' here
}
}
Always pass the IDbSetting object when using the
dbFieldsargument.