我对 Rhino ETL 了解不多,但 FileHelpers 有一个ClassBuilder
允许您在运行时生成记录类。有关一些示例,请参阅文档。
所以很容易生成一个类似下面的类:
SqlCommand command = new SqlCommand("SELECT TOP 1 * FROM Customers;", connection);
connection.Open();
// get the schema for the customers table
SqlDataReader reader = command.ExecuteReader();
DataTable schemaTable = reader.GetSchemaTable();
// create the FileHelpers record class
// alternatively there is a 'FixedClassBuilder'
DelimitedClassBuilder cb = new DelimitedClassBuilder("Customers", ",");
cb.IgnoreFirstLines = 1;
cb.IgnoreEmptyLines = true;
// populate the fields based on the columns
foreach (DataRow row in schemaTable.Rows)
{
cb.AddField(row.Field<string>("ColumnName"), row.Field<Type>("DataType"));
cb.LastField.TrimMode = TrimMode.Both;
}
// load the dynamically created class into a FileHelpers engine
FileHelperEngine engine = new FileHelperEngine(cb.CreateRecordClass());
// import your records
DataTable dt = engine.ReadFileAsDT("testCustomers.txt");