Do I need to call SaveChanges when using EFCore.BulkExtensions

c# ef-core-2.0 entity-framework-core

Question

I started using EFCore.BulkExtensions for ef bulk operations, and it is working very nice.

(see https://github.com/borisdj/EFCore.BulkExtensions/)

do I need to call also to SaveChanges:

        using (var db = new ReportingContext())
        {
            db.BulkInsertOrUpdate(entities);
            db.SaveChanges();
        }

or this is good enough?

        using (var db = new ReportingContext())
        {
            db.BulkInsertOrUpdate(entities);
        }
1
3
9/5/2018 9:35:59 AM

Accepted Answer

The page from the link contains the following

Under the hood uses SqlBulkCopy for Insert, for Update/Delete combines BulkInsert with raw Sql MERGE (MsSQL 2008+).

So the answer is no, you don't need to call SaveChanges because EFCore.BulkExtensions works directly with the database (SqlServer). The entities you pass may not even be attached (tracked) to the context. It uses the context just to get entity model metadata and connection/transaction info.

5
9/5/2018 9:35:23 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