具有条件更新的DynamoDBContext [英] DynamoDBContext with conditional update

查看:150
本文介绍了具有条件更新的DynamoDBContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在使用亚马逊对象持久性模型,并使用DynamoDBContext进行操作(CURD和执行查询)。我需要知道如何使用DynamoDBContext使用条件更新。并且应该是异步的。

in my application i'm using amazon object persistence model and use DynamoDBContext for operations(CURD and execute queries). i need to know that how can i use conditional update using DynamoDBContext. and it should be asynchronous.

我知道使用亚马逊低级API的方式。

I know the way of doing it using amazon low-level API.

我的应用程序是使用C#Dot Net(4.5)开发的。
谢谢。

my application is developed using C# Dot Net(4.5) thank you.

推荐答案

.NET异步DynamoDBContext.Save调用使用SaveHelper
SaveHelper 使用operationConfig调用UpdateHelper
作为DynamoDBOperationConfig 具有ConditionalOperator字段,您可以尝试使用该字段对属性值进行放置/更新。请注意,您只能在此调用中对一项执行条件。如果这样做,将无法覆盖已经存在的项目,从而强制执行唯一性。我建议您为哈希密钥使用UUID而不是递增数字。尽管原子计数器在以下情况下受支持一个项目,表的所有项目均不支持它们。对于DynamoDBContext.Save调用不支持的条件写入,您始终可以使用低级API 条件表达式来执行条件写操作。

.NET Async DynamoDBContext.Save call uses SaveHelper. SaveHelper calls UpdateHelper with an operationConfig. As DynamoDBOperationConfig has a ConditionalOperator field, you may try using that to condition puts/updates on attribute values. Note that you can only enforce conditions on one item in this call. If you do that, you will not be able to overwrite an item that already exists, thereby enforcing uniqueness. I suggest you use a UUID instead of an incrementing number for your hash key though. While atomic counters are supported in the context of one item, they are not supported across all the items of a table. For conditional writes not supported by the DynamoDBContext.Save call, you can always use the low-level API with a condition expression to perform your conditional write.

这篇关于具有条件更新的DynamoDBContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆