Nofield
Nofield

Reputation: 81

Does ef core plus support batch update with minus?

I want to update stock quantity, such as +1, because so many requests do the same thing, and I don't want to lock the row for performance, then SQL which I wanted is :

Update Stock 
Set qty = qty + 1
where id = xxxx

Does Entity Framework Core Plus support it, or how to implement it?

Upvotes: 0

Views: 99

Answers (1)

Svyatoslav Danyliv
Svyatoslav Danyliv

Reputation: 27336

I think its obvious

db.Stock
  .Where(x => x.Id == id)
  .Update(x => new Stock { qty = x.qty + 1 });

Upvotes: 2

Related Questions