c# - Using Fastmember to bulk insert only selected columns -
i have application being used insert large amounts of data (up 250,000 records per file) file table has several computed columns. there way select columns fastmember inserts data don't try writing computed columns?
using (sqlbulkcopy bcp = new sqlbulkcopy(yourconnectionstring)) { // +1 marc gravell neat little library mapping // because datatable isn't available until .net standard library 2.0 using (var datareader = objectreader.create(yourlistofobjects, nameof(yourclass.property1), nameof(yourclass.property2))) { bcp.destinationtablename = "yourtablenameinsql"; bcp.columnmappings.add(new sqlbulkcopycolumnmapping("property1", "mycorrespondingtablecolumn")); bcp.columnmappings.add(new sqlbulkcopycolumnmapping("property2", "tableproperty2")); await bcp.writetoserverasync(datareader).configureawait(false); } }
Comments
Post a Comment