将实体数据更新到Azure存储表 [英] Updating entity data to Azure storage table
问题描述
在一种情况下,我将数据插入/更新到Azure存储表2中的值MyValue和MyDate.
I have a scenario where I insert/update data to Azure storage table 2 values MyValue and MyDate.
在少数情况下,我只需要更新1个值MyValue而不是MyDate.
There are few scenarios where I have to update only 1 value MyValue and not MyDate.
但是当我执行更新操作时,它会更新两个值.它会更改myValue,但会使MyDate为null.
But When I do update operation, it updates bothe the values. It changes myValue but makes MyDate to null.
更新中是否有任何操作可以跳过MyDate更新并保持其原样?
Is there any operation in update where I can skip MyDate update and keep its value as it is?
public class MyEntity : TableEntity
{
public MyEntity(string partitionKey, string rowKey) :
base(partitionKey, rowKey)
{
}
public string MyValue { get; set; }
public DateTime MyTime { get; set; }
}
此代码插入或替换数据
var entity = new MyEntity(partitionKey, rowKey)
{
MyValue = "test my value",
MyTime = DateTime.Now();
};
AddEntity(entity);
public void AddEntity(MyEntity entity)
{
CloudTable table = _tableClient.GetTableReference("myAzureStorageTableName");
TableOperation insertOp = TableOperation.InsertOrReplace(entity);
table.Execute(insertOp);
}
推荐答案
您可以利用合并操作.请注意,您应将ETag设置为"*".如果您不想在更新实体之前先阅读它.
You can leverage Merge operation. Please note that you should set ETag to "*" if you don't want to read the entity before updating it.
参考文献:
这篇关于将实体数据更新到Azure存储表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!