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.
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
.
See this article on SubmitChanges() .
Your changes are not transmitted to the server until you explicitly call SubmitChanges on the DataContext.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.