-
Notifications
You must be signed in to change notification settings - Fork 127
Data Reading
Martin Willey edited this page Aug 28, 2017
·
1 revision
This library is primarily to read the schema, not the data. But you can read the rows from the data. This doesn't work in .net Core 1, but it works in .net full framework and .net Core 2.
Use the DatabaseSchemaReader.Data.Reader
You can be returned a DataTable (that's why it doesn't work with Core 1), or use a function that takes an IDataRecord.
In .net full framework, use this API:
var dbReader = new DatabaseReader(connectionString, providername);
var table = dbReader.Table("Categories");
var reader = new Reader(table, connectionString, providername);
reader.PageSize = 10; //default is 1000
//1. get a DataTable
var dataTable = reader.Read();
//2. pass in a function
reader.Read(record => {
var name = record["CategoryName"].ToString();
//... do something with name
return true;
});
The feature is only available in Core 2.0 (and if the database provider is netstandard 2.0) In .netStandard 2.0, use this API:
using (var connection = new SqlConnection(connectionString))
{
var dr = new DatabaseSchemaReader.DatabaseReader(connection);
var table = dbReader.Table("Categories");
var reader = new Reader(table);
reader.PageSize = 10; //default is 1000
//1. get a DataTable
var dataTable = reader.Read(connection);
//2. pass in a function
reader.Read(connection, record => {
var name = record["CategoryName"].ToString();
//... do something with name
return true;
});
}