c# - Insert a linq-query into DataTable Rows dynamically -
i looking way dynamically insert fields of linq-query (excluding id-field) rows of datatable matching columns. end goal bulkinsert/sqlbulkcopy datatable database.
var clearing = line in readcsvfile(e.fullpath) select new clearingdata { //about 200 fields set here snip }; //create datatable bulk inserting datatable dt = new datatable(); //insert appropriate columns datatable foreach(var property in typeof(clearingdata).getproperties().where(x => x.name != "csvreportid")) { dt.columns.add(property.name, nullable.getunderlyingtype(property.propertytype) ?? property.propertytype); } foreach(clearingdata clear in clearing) { //something dt.rows.add(all elements in clear.where(field != "id")) }
clearingdata mapped type entity framework, clearing linq-query imports 200-meg .csv , creates anonymous type containing rows , fields. there 200 fields, why don't want add rows hand.
thanks in advance!
Comments
Post a Comment