With FastMember, you can do this without ever needing to go via DataTable
(which, in my tests, more-than-doubles the performance):
using(var bcp = new SqlBulkCopy(connection))
using(var reader = ObjectReader.Create(data, "Id", "Name", "Description"))
{
bcp.DestinationTableName = "SomeTable";
bcp.WriteToServer(reader);
}
Note that ObjectReader
can also work with non-generic sources, and it is not necessary to specify the member-names in advance (although you probably want to use the ColumnMappings
aspect of SqlBulkCopy
if you don't specify them in the ObjectReader
itself).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…