I am developing a C# Azure application using C#, .NET 5.0 and Microsoft.Azure.Cosmos.Table version 1.0.8. I want to do the following:
- Look in the table storage for a row/entity with a particular partition key and row key.
- If it exists, then return the entity.
- If it doesn't exist, then create one, store it in the table storage and return it.
I want to do this atomically to avoid race conditions (i.e., if two threads try to do this simultaneously, I want to guarantee that they return the same value and that only one entity gets stored in the table storage).
TableOperation has InsertOrMerge and InsertOrReplace, but they don't seem to be what I want. Both of them, as far as I can see, will prefer the last value written, which I don't want. I want it to keep the first value that gets written (so that all concurrent threads will return the same value).
How can I do this?
Thanks in advance!