I need to insert a large amount of data into SqlServer 2008. My project is based on linq-to-sql.
I am processing a csv file with 100,000 lines. Each line is mapped to an object Order. Orderalso contains a set of objects Categoryand Code. I need to map each line to an object in order to check it.
Then I need to insert all these objects into the database.
List<Order> orders = Import("test.csv");
db.Orders.InsertAllOnSubmit(orders);
db.SubmitChanges();
OR
foreach(Order order in orders)
db.Orders.InsertOnSubmit(order);
db.SubmitChanges();
Both ways are slow. Is there a workaround? I can use a different approach than l2sql for this task.
I read about the SqlBulkCopy class - would handle insert children ?
source
share