© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
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));
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Efcore help with 2 databases
C#CC# / help
3y ago
Issues with EFCore
C#CC# / help
3y ago
✅ EFCore Tables with inharitance
C#CC# / help
3mo ago