Fastest Way of Inserting in Entity Framework

前端 未结 30 2114
鱼传尺愫
鱼传尺愫 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:42

    Have you ever tried to insert through a background worker or task?

    In my case, im inserting 7760 registers, distributed in 182 different tables with foreign key relationships ( by NavigationProperties).

    Without the task, it took 2 minutes and a half. Within a Task ( Task.Factory.StartNew(...) ), it took 15 seconds.

    Im only doing the SaveChanges() after adding all the entities to the context. (to ensure data integrity)

提交回复
热议问题