No optimistic concurrency check, when having a RowVersion column and executing the BulkUpdate() method
AntonZhmyrov opened this issue · 2 comments
AntonZhmyrov commented
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?
mtanneryd commented
Hi and thanks for the feedback. I'll look into it as soon as I can! If
possible, please provide a sample of code or pseudocode that I could use to
reproduce the error.
/Måns
Måns Tånneryd
Tånneryd IT AB
Barrskogsvägen 19
186 53 Vallentuna
+46-705140093
https://se.linkedin.com/in/manstanneryd
*https://github.com/mtanneryd/ef6-bulk-operations
<https://github.com/mtanneryd/ef6-bulk-operations>*
Den mån 17 maj 2021 kl 13:33 skrev AntonZhmyrov ***@***.***>:
… 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?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#34>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2BSRMCDKD6WOD3KANVNDTTOD5HNANCNFSM45AIXF6A>
.
AntonZhmyrov commented
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);