Pou*_*sen 0 azure azure-table-storage
如果ETag尚未更改,如何使用Azure表存储实体的ETag更新实体?
例:
var query = (from ent in cloudservicetable.CreateQuery<CloudServiceTableEntity>()
where ent.PartitionKey == "test"
&& ent.Status == "creating"
&& ent.Counter> 0
select ent).AsTableQuery();
var candidates = query.OrderByDescending(s=>s.Counter).ToList();
bool found = false;
while (!found && candidates.Any())
{
//Find best candidate
var candidate = candidates.First();
//If we can decrement the count with out the entity have been changed
//it is a acceptable candidate.
candidate.Counter--;
var opr = TableOperation.Merge(candidate);
// cloudservicetable.ExecuteAsync(opr)
// How do I only do the merge if the etag have not changed?
//TODO If changed remove/update the candidate list
}
// if found we have a candidate
Run Code Online (Sandbox Code Playgroud)
对于条件合并,您无需执行任何操作。如果在合并操作期间不匹配,您的代码将引发错误(PreCondition-失败Http Status Code 412)ETag。因此,您上面的代码可以正常工作。
对于无条件合并,您需要手动将ETag实体的属性设置为*。
| 归档时间: |
|
| 查看次数: |
1293 次 |
| 最近记录: |