使用LINQ到SQL BULK INSERT [英] bulk insert with linq-to-sql
问题描述
我有一个查询,看起来像这样:
I have a query that looks like this:
using (MyDC TheDC = new MyDC())
{
foreach (MyObject TheObject in TheListOfMyObjects)
{
DBTable TheTable = new DBTable();
TheTable.Prop1 = TheObject.Prop1;
.....
TheDC.DBTables.InsertOnSubmit(TheTable);
}
TheDC.SubmitChanges();
}
这基本上查询插入一个列表转换成使用LINQ到SQL数据库。现在,我读过网上说L2S不支持批量操作。
通过在一个写在同一时间或全部插入每个元素是否我的查询工作?
This query basically inserts a list into the database using linq-to-sql. Now I've read online that L2S does NOT support bulk operations. Does my query work by inserting each element at a time or all of them in one write?
感谢您的澄清。
推荐答案
术语批量插入
通常是指基于SQL Server特定的超快速bcp <一个href=\"http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx\">SqlBulkCopy实现。它是建立在<顶部href=\"http://stackoverflow.com/questions/4230370/inserting-bulk-data-in-sql-oledb-irowsetfastload-vs-ado-net-sqlbulkcopy\">IRowsetFastLoad.
The term Bulk Insert
usually refers to the SQL Server specific ultra fast bcp based SqlBulkCopy implementation. It is built on top of IRowsetFastLoad.
的LINQ-2-SQL不使用这种机制,任何的条件下实现的插入。
Linq-2-SQL does not implement insert using this mechanism, under any conditions.
如果您需要批量数据装载到SQL Server和需要它要快,我会建议使用手工编码的SqlBulkCopy
If you need to bulk load data into SQL Server and need it to be fast, I would recommend hand coding using SqlBulkCopy.
的LINQ-2-SQL将尝试进行一些优化技术来加快多个插入,但它仍然会功亏一篑许多微奥姆斯的(即使没有微奥姆斯我所知道的实施SqlBulkCopy的)
Linq-2-SQL will attempt to perform some optimisations to speed up multiple inserts, however it still will fall short of many micro ORMs (even though no micro ORMs I know of implement SqlBulkCopy)
这篇关于使用LINQ到SQL BULK INSERT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!