2

In the past, I always use Class SqlBulkCopy to complete bulk insert. But I don't know how to implement it using Linq to SQL. If inserted one by one, Efficiency will be very low.
Any good ideas?
Thanks in advance and sorry for my poor English.

2 Answers 2

4

Simple: you don't. You just use SqlBulkCopy. LINQ-to-SQL is simply a tool. SqlBulkCopy is a tool. Use the right tool for each job. Sometimes that means using something that isn't LINQ-to-SQL. This might mean creating a DataTable (or a spoof IDataReader if you are feeling ambitious) to represent the data; look perhaps at Convert generic List/Enumerable to DataTable? to get from your typed objects to a DataTable you can feed to SqlBulkCopy.

Sign up to request clarification or add additional context in comments.

1 Comment

+1. O/R mappers serve a specific need. Dont't abuse a tool. SqlBulkCopy is unbeatable for bulk inserts.
0

See this article on SubmitChanges().

Your changes are not transmitted to the server until you explicitly call SubmitChanges on the DataContext.

2 Comments

Submitchanges does not do bulkinsert, but one insert statement per record.
@Pleun: Thanks, I didn't realize.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.