繁体   English   中英

将实体数据更新到 Azure 存储表

[英]Updating entity data to Azure storage table

我有一个场景,我将数据插入/更新到 Azure 存储表 2 值 MyValue 和 MyDate。

在少数情况下,我只需要更新 1 个值 MyValue 而不是 MyDate。

但是当我进行更新操作时,它会更新两个值。 它更改 myValue 但使 MyDate 为 null。

更新中是否有任何操作可以跳过 MyDate 更新并保持其值不变?

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 设置为“*”。

参考资料:

  1. 合并实体 REST API
  2. .NET 库中的 TableOperation.Merge 方法

这里InsertOrMergeMerge操作都可以。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM