如果项目不存在或其他字段等于特定值,则要更新的DynamoDB表达式

时间:2018-07-02 15:02:42

标签: c# .net amazon-dynamodb

当我尝试进行条件更新时出现以下错误:

  

无效的ConditionExpression:语法错误;令牌:“-”,附近:“ PageRouteee1181aa-8035”

我有以下课程:

public class RestaurantPageRouteItem
{
    [DynamoDBHashKey]
    public string PageRoute { get; set; }

    public string RestaurantId { get; set; }
}

然后我创建以下表达式:

new Expression
{
    ExpressionStatement = $"attribute_not_exists({item.PageRoute}) OR {item.RestaurantId} = :restaurantid",
    ExpressionAttributeValues =
    {
        [":restaurantid"] = item.RestaurantId
    }
}

1 个答案:

答案 0 :(得分:0)

设法提出以下建议:

new Expression {
 ExpressionStatement =
  "(attribute_not_exists(#ID) OR :id = #ID) OR " +
  "(attribute_not_exists(PageRoute))",
  ExpressionAttributeValues = {
   [":id"] = item.RestaurantId
  },
  ExpressionAttributeNames = {
   ["#ID"] = "RestaurantId"
  }
}