Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to call SaveChanges when using EFCore.BulkExtensions

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);
        }
like image 412
Aviko Avatar asked Sep 05 '18 07:09

Aviko


1 Answers

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.

like image 143
Ivan Stoev Avatar answered Oct 16 '22 15:10

Ivan Stoev