开发者

EF code first inserting many rows

开发者 https://www.devze.com 2023-02-12 17:11 出处:网络
I\'m using EF code first and I need to insert many rows into a table, a couple of thousand records, I have in a generic list. Just doing a foreach loop and addi开发者_开发问答ng each entity to the tab

I'm using EF code first and I need to insert many rows into a table, a couple of thousand records, I have in a generic list. Just doing a foreach loop and addi开发者_开发问答ng each entity to the table and finish with a SaveChanges() takes quite a while.

Is there a bulky way of doing this with EF or code first or should I do SqlCommand or SqlBulkCopy instead? Also, is there something I can switch off in EF code first to make the inserts faster?

Thanks for the help!


You can call SaveChanges() less often.

However, nothing you can do with the EF will approach the performance of something like SqlBulkCopy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号