How to improve the Update operation performance in Entity Framework 6

c# c#-4.0 entity-framework entity-framework-6 performance

Question

We are trying to update the 20000 records in single commit which is taking more than 30 minutes. We are thinking to reduce the records counts and implementing the batch process which will commit the 1000 records. Can any provide the suggestion to improve the performance?

1
1
10/15/2018 10:29:11 AM

Popular Answer

By default, EF does 1 query for single update. You can write stored procedure accepting table valued parameter, thus updating multiple rows with single query, reducing roundtrip overhead. Also for bulk inserts you can use SqlBulkCopy class.

Update: alternatively you can use 3rd party libraries to do this. Something like https://entityframework-plus.net/?z=ef-extended and https://entityframework-extensions.net/ I also used simple wrapper over SqlBulkCopy for bulk inserts.

Update2: Example from Microsoft how to use Table Valued Parameters: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/table-valued-parameters That is for ADO.Net, but similar approach is possible with EF.

1
10/15/2018 10:54:31 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow