Azure SDK for Java – 更新表实体会添加以 “odata” 开头的字段名称。

huangapple go评论129阅读模式
英文:

Azure SDK for Java - Updating a table entity adds fields having names starting with odata

问题

我正在使用Azure SDK for Java并与Azure存储表一起工作。
我试图更新行中的字段,我正在使用的代码如下:

TableClient tableClient = getTableClient();

String myPartitionKey = "partitionkey";
String myRowKey = "rowkey";

List propertiesToSelect = new ArrayList<>();
propertiesToSelect.add("field9");
propertiesToSelect.add("field10");

Response response = tableClient.getEntityWithResponse(myPartitionKey, myRowKey, propertiesToSelect,
Duration.ofSeconds(5), null);

TableEntity tableEntity = response.getValue();

Map<String, Object> properties = tableEntity.getProperties();
properties.put("field9", "value9");
properties put("field10", "value10");
tableClient.updateEntity(tableEntity, TableEntityUpdateMode.MERGE);

发生的情况是字段值得到更新,但同时一些以"odata"开头的字段也被添加到行中。

我如何阻止这些字段被添加到行中?

感谢您的帮助。

英文:

I am using the Azure SDK for Java and working with Azure Storage Tables.
I am trying to update fields in a row and the code I am using is as below

    TableClient tableClient = getTableClient();

    String myPartitionKey = &quot;partitionkey&quot;;
    String myRowKey = &quot;rowkey&quot;;

    List&lt;String&gt; propertiesToSelect = new ArrayList&lt;&gt;();
    propertiesToSelect.add(&quot;field9&quot;);
    propertiesToSelect.add(&quot;field10&quot;);

    Response&lt;TableEntity&gt; response = tableClient.getEntityWithResponse(myPartitionKey, myRowKey, propertiesToSelect,
            Duration.ofSeconds(5), null);

    TableEntity tableEntity = response.getValue();

    Map&lt;String, Object&gt; properties = tableEntity.getProperties();
    properties.put(&quot;field9&quot;, &quot;value9&quot;);
    properties.put(&quot;field10&quot;, &quot;value10&quot;);
    tableClient.updateEntity(tableEntity, TableEntityUpdateMode.MERGE);

What is happening is that the field values are getting updated but along with there some fields having names starting with "odata" are also being added to the rows.

How do I prevent these fields from being added to the rows?

Thanks for your help.

答案1

得分: 0

解决方案是创建一个具有相同分区键和行键的新实体。然后添加我们要更新的属性,然后以合并模式更新实体。

TableEntity tableEntity = new TableEntity("partitionKey", "rowKey");
tableEntity.addProperty("Version", version);
tableEntity.addProperty("TimeStamp", myTimestamp);
tableClient.updateEntity(tableEntity, TableEntityUpdateMode.MERGE);
英文:

The solution was to create a new entity with the same partition key and row key. Then add the property we are attempting to update and then update the entity in the merge mode.

        TableEntity tableEntity = new TableEntity(&quot;partitionKey&quot;, &quot;rowKey&quot;);
        tableEntity.addProperty(&quot;Version&quot;, version);
        tableEntity.addProperty(&quot;TimeStamp&quot;, myTimestamp);
        tableClient.updateEntity(tableEntity, TableEntityUpdateMode.MERGE);

huangapple
  • 本文由 发表于 2023年3月15日 19:15:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743958.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定