for ETag in ITableEntity MSDN says: Gets or sets the entity's current ETag. Set this value to '*' in order to blindly overwrite an entity as part of an update operation.
I am unable to undersatnd the purpose of this property, please explain why and when we can use this property.
ETag is not the timestamp, or at least not anymore. There is another Timestamp property that is when the record was last updated. The ETag is used for concurrency. If you load a table entity and want to update it, you pass to update the ETag from when you loaded the value and it will update the entity only if that ETag matches what is stored.
Why do you care? Well if you have multiple users editing the same item on a form at the same time, you don't want one users change to overwrite the other user without the second user being notified that they are overwriting data that has been changed since they loaded it.
Example: user 1 and user 2 load an edit page at the same time. User 1 changes a value for field 1 and saves the item. After user 2 has had the item open a bit longer user 2 makes a change to unrelated field 2 and unknowingly the outdated field 1 is being saved with their update. User 2 does not know they are discarding a change by user 1 unless you tell them. So what you should do is show an error that user 1 changed it already and are they sure they want to overwrite user 1 changes or if they want to see those changes first.
This is accomplished by both user 1 and user 2 storing the ETag from when the record was loaded hidden on your form display. When each user attempts a save you can pass that ETag to the server with the updated data. How does this tell you user 2 is changing an out of date record? Because every change to a record updates the ETag stored for that record. So when user 2 tries to save the ETag you send with their changes won't match and Azure will tell you so you can handle what should be done.
Now if you don't care that user 2 may overwrite user 1 changes, then pass "*" with the save and Azure won't give an error when the ETag does not match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With