Fastest Way of Inserting in Entity Framework

前端 未结 30 2756
鱼传尺愫
鱼传尺愫 2020-11-21 05:23

I\'m looking for the fastest way of inserting into Entity Framework.

I\'m asking this because of the scenario where you have an active TransactionScope a

30条回答
  •  生来不讨喜
    2020-11-21 05:52

    All the solutions written here don't help because when you do SaveChanges(), insert statements are sent to database one by one, that's how Entity works.

    And if your trip to database and back is 50 ms for instance then time needed for insert is number of records x 50 ms.

    You have to use BulkInsert, here is the link: https://efbulkinsert.codeplex.com/

    I got insert time reduced from 5-6 minutes to 10-12 seconds by using it.

提交回复
热议问题