英文:
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.add("field9");
propertiesToSelect.add("field10");
Response
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 = "partitionkey";
String myRowKey = "rowkey";
List<String> propertiesToSelect = new ArrayList<>();
propertiesToSelect.add("field9");
propertiesToSelect.add("field10");
Response<TableEntity> 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);
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("partitionKey", "rowKey");
tableEntity.addProperty("Version", version);
tableEntity.addProperty("TimeStamp", myTimestamp);
tableClient.updateEntity(tableEntity, TableEntityUpdateMode.MERGE);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论