Search code examples
c#entity-framework-6entity-framework-plusentity-framework-extensions

Entity Framework extension's batch operations vs EFE's bulk operations


I was looking into Entity Framework extensions for bulk operations and I found from the same developers EF Plus. Now EFE has bulk operations which are payed and EF PLus has Batch operations, which claim to perform bulk update and delete only, but are called batch operations. So what is the difference between the EFE's bulk operations and EF plus batch operations?


Solution

  • Disclaimer: I'm the owner of the project Entity Framework Extensions

    Disclaimer: I'm the owner of the project Entity Framework Plus

    There is a huge difference between methods that are called Bulk Operation and Batch Operation.

    Batch Operation

    Bach operation performs an operation in the database without loading data in the context. In short, everything is done on the database side.

    Both libraries support it and it will eventually be supported in one library (for free no matter the library decision)

    In EFE, methods are named:

    • DeleteFromQuery
    • UpdateFromQuery

    In EF+, methods are named:

    • Delete
    • Update

    Bulk Operation

    Bulk Operation only exists in EFE. They are immediate operations that take a list of entities and saves them with the database.

    • Bulk SaveChanges
    • Bulk Insert
    • Bulk Delete
    • Bulk Update
    • Bulk Merge

    Example

    // Easy to use
    context.BulkSaveChanges();
    
    // Easy to customize
    context.BulkSaveChanges(bulk => bulk.BatchSize = 100);
    
    // Perform Bulk Operations
    context.BulkDelete(customers);
    context.BulkInsert(customers);
    context.BulkUpdate(customers);
    
    // Customize Bulk Operations
    context.BulkInsert(customers, options => {
       options => options.IncludeGraph = true;
    });
    context.BulkMerge(customers, options => {
       options.ColumnPrimaryKeyExpression = 
            customer => customer.Code;
    });