简体   繁体   中英

DynamoDB expression to Update if item does not exist or other field equals certain value

I get the following error when I try to do a conditional update:

Invalid ConditionExpression: Syntax error; token: "-", near: "PageRouteee1181aa-8035"

I have the following class:

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

    public string RestaurantId { get; set; }
}

And Im creating the following expression:

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

Managed to come up with the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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