mtanneryd/ef-bulk-operations

No optimistic concurrency check, when having a RowVersion column and executing the BulkUpdate() method

AntonZhmyrov opened this issue · 2 comments

Hello!

Thank you for a great and fast library!

Unfortunately, I have run into an issue, when using the BulkUpdate() method, it does not enforce the optimistic concurrency check.
When having the 'RowVersion' column, and in concurrent scenarios, BulkUpdate() just overwrites the changes, ignoring the fact that the same version of data was already modified by different source.

Could you help with that please?

Sure, it is fairly easy to reproduce. Here is some pseudocode:

public class Item
{
    public long Id { get; set; }

    public string Name { get; set; }

    public byte[] RowVersion { get; set; }
}

// query for item with rowversion using EF 6
var item = await _dbContext.Items.FirstOrDefaultAsync();

// update name
item.Name = "New Name";

// save the updated entity
_dbContext.SaveChangesAsync();

var updateRequest = new BulkUpdateRequest
{
     Entities = new List<Item> { item } as IList,
     UpdatedColumnNames = new[]
     {
         nameof(Item.Name);
     }
};

// do bulk update on already updated entity, row version is different for it in DB, but no exception thrown, and changes are //overwritten
_dbContext.BulkUpdateAll(updateRequest);