2

So I'm hitting my webservice to save a row in the database if the id doesn't already exist. So I do this in two steps. First I run a select on the context to bring back the entity with the given id. If that returns null, I create a new entity and call saveChanges. This works perfectly almost always. However, when there are multiple requests hitting the webserver at the same time, there is a chance that 2 requests could run at pretty much the same time. When this happens, there is the chance that they both create a row. This is actually happening.

How would you handle this situation?

p.s. I'm using EntityFramework Core.

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
FeeFiFoFum
  • 1,719
  • 1
  • 11
  • 18

0 Answers0