[{"data":1,"prerenderedAt":89},["ShallowReactive",2],{"/2025/10/10-entity-framework-(ef)-slow-insert-and-sqlbulkcopy-to-the-rescue":3},{"id":4,"title":5,"body":6,"date":80,"description":76,"extension":81,"meta":82,"navigation":83,"path":84,"robots":85,"seo":86,"stem":87,"__hash__":88},"posts/2025/10/10 Entity-Framework-(EF)-slow-insert-and-SqlBulkCopy-to-the-rescue.md","10 Entity Framework (EF) Slow Insert And SqlBulkCopy To The Rescue",{"type":7,"value":8,"toc":77},"minimark",[9,18,25,28,43,45,48,58,60,63],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"entity-framework-ef-slow-insert-and-sqlbulkcopy-to-the-rescue","Entity Framework (EF) Slow Insert and SqlBulkCopy to the Rescue",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 11/1/2018.",[26,27],"br",{},[22,29,30,31,42],{},"There was a need to insert bulk data into the database and we are using Entity Framework as our ORM strategy. However, bulk insert took forever. Disabling Auto Detect Changes helps a little. So I decided to look into SqlBulkCopy and ended up writing one for Entity Framework. It is generic enough and can be found in ",[32,33,36],"span",{"className":34},[35],"text-blue-600",[37,38,39],"a",{"href":39,"rel":40},"https://gist.github.com/nikyodo85/b82ffd56bb2f0d45a9860dadcdfdc01d",[41],"nofollow",".",[26,44],{},[22,46,47],{},"It works well so far. Some of the drawbacks are:",[49,50,51,55],"ul",{},[52,53,54],"li",{},"It won't be able to auto insert relationship",[52,56,57],{},"No validation check",[26,59],{},[22,61,62],{},"But very fast. To use it will be very similar to SqlBulkCopy:",[64,65,66],"code-block",{},[67,68,73],"pre",{"className":69,"code":71,"language":72},[70],"language-text","Dim efSqlBulkCopy As New EFSqlBulkCopy(Of MyEntityClass)(myDbContext)\nefSqlBulkCopy.WriteToServer(listOfMyEntityClass)\n","text",[74,75,71],"code",{"__ignoreMap":76},"",{"title":76,"searchDepth":78,"depth":78,"links":79},2,[],"2025-10-10T00:00:00.000Z","md",{},true,"/2025/10/10-entity-framework-(ef)-slow-insert-and-sqlbulkcopy-to-the-rescue",null,{"title":5,"description":76},"2025/10/10 Entity-Framework-(EF)-slow-insert-and-SqlBulkCopy-to-the-rescue","-AcYg7RDdok6rJUsjWqlqgMvU-v6llIQZxUu2ESC3KA",1785167452927]