I may have found a solution. Will accept this if nobody has a better answer.
I tried to add If-Match
header of the OperationContext
, with the Etag as the value. This worked. I thought this was an automatically added thing, but apparently not.
testtable.Execute(
TableOperation.InsertOrReplace(firstRetrieve),
null,
new OperationContext {
UserHeaders = new Dictionary<String, String>
{
{ "If-Match", firstRetrieve.ETag }
}
}
);
Now, when using null
as ETag, I can InsertOrReplace, and it also properly checks ETag if it's something else.
Note that if I use *
as ETag, I get a 404 exception if the entity doesn't exist. So use null
to get the intended functionality. Or just detect *
and don't add the header.
EDIT:
Caveat: If you'd want to insert a new item (ETag == null
) but still want to get an exception code 409 conflict if it already exists, you must use the Insert
operation instead of the InsertOrReplace
operation.