C#C
C#3y ago
linqisnice

❔ EFCore, help with atomic update along with complex conditions

Basically, I've been trying to do something like this...

var composite = await _dbContext.Inventories.Where(i => requestedQuantity.Select(x => x.AccommodationId).Contains(i.AccommodationId) && nightsInterval.Contains(i.Date)) 
            && requestedQuantity.All(x => x.Value <= i.TotalQuantity - i.TotalReserved).ExecuteUpdateAsync(
            setters => setters.SetProperty(
               i => i.TotalReserved,
               i => i.TotalReserved + 1));


in one atomic operation, to ensure read and write-lock on the affected items. but ot's not possible, since linq to entities cant deal with: requestedQuantity.All(x => x.Value <= i.TotalQuantity - i.TotalReserved)

I've also tried a loop variation, won'tt work properly.

i've been looking at transactions, but they would serialize not per accommodation but the entire method, which would lead to a massive performance bottleneck on this m
ethod. I don't know any SQL so I wouldn't know where to start. Any advice?
Was this page helpful?