I'm looking for the fastest way of inserting in Entity Framework.
I'm asking this because of the scenario where you have an active TransactionScope and the insertion is huge (4000+). It can potentially last more than 10 minutes (default timeout of transactions), and this will lead to an incomplete transaction.
Currently I am doing it as follows. Is there a more efficient way?
- Creating the
TransactionScope - instantiating the
DBContext - Opening the connection
- In a for-each statement doing the insertions and SavingChanges (for each record).
NOTE: TransactionScope and DBContext are in using statements, and I'm closing the connection in a finally block.