[英]What is the fastest way to save data in SQL Server using C#?
I am currently working on a small .NET app in C#, that fetches data through some web service. 我目前正在使用C#开发一个小型.NET应用程序,该应用程序通过某些Web服务获取数据。
The data is represented in objects, so it would have been logical to store the data in a document based database, but there is a demand to use SQL Server. 数据以对象表示,因此将数据存储在基于文档的数据库中是合乎逻辑的,但是有使用SQL Server的需求。
So what might be the fastest way to insert many thousands, perhaps millions of rows into a database. 因此,将数以千计,也许数百万行插入数据库的最快方法可能是。
I an open to any framework, that might could support that, but I haven't been able to find any benchmarking on this eg on Entity Framework. 我对任何框架都持开放态度,这可能会支持这一框架,但是我无法在此上找到任何基准,例如在实体框架上。
To iterate over the data an do an insert per row is simply to slow, then it would be quicker to dump the data in a file, and then do a bulk import using SSIS, but for this scenario I would rather avoid that, and keep all logic in the C# app. 要遍历数据,每行插入一次只是为了减慢速度,然后将数据转储到文件中,然后使用SSIS进行批量导入会更快,但是对于这种情况,我宁愿避免这种情况,并保持C#应用程序中的所有逻辑。
You might want to use the SqlBulkCopy
class. 您可能要使用
SqlBulkCopy
类。 It is quite efficient for large data. 对于大数据而言,这非常有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.