Fastest Way of Inserting in Entity Framework

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

    The secret is to insert into an identical blank staging table. Inserts are lightening quick. Then run a single insert from that into your main large table. Then truncate the staging table ready for the next batch.

    ie.

    insert into some_staging_table using Entity Framework.
    
    -- Single insert into main table (this could be a tiny stored proc call)
    insert into some_main_already_large_table (columns...)
       select (columns...) from some_staging_table
    truncate table some_staging_table
    

提交回复
热议问题