10
votes

When performing an InsertOrReplace operation on Azure Table Storage, is there any way to determine whether the entity was freshly inserted or if a replace occurred?

TableOperation insertOperation = TableOperation.InsertOrReplace(entity);
TableResult result = table.Execute(insertOperation);

TableResult does not seem to indicate this.

1
I don't think so. I'm curious why you would want to know that.Gaurav Mantri
For auditing reasons.Dave New
I see. Thanks. You could implement InsertOrReplace on your own if you would like to do auditing rather than relying on Table Storage InsertOrReplace functionality.Gaurav Mantri
If audit is requirement that my approach would be to have an Immutable storage. Meaning that once something is in the Storage, it stays there and does not change. If something needs to be update - a new version is created and the old still stays. Or as Gaurav mentioned, create your own version of InsertOrReplace where you first log what happens (and check for existence) and then add new record or update an entityastaykov

1 Answers

9
votes

InsertOrReplace will result with HttpStatusCode.NoContent on a successful insert or replace. This is a slight deviation from HTTP that suggests 201 (HttpStatusCode.Created) should be the result if something is created or inserted.