Reputation: 1777
I am trying to learn to use DynamoDB with C# I have Partial updates, Put, Delete working. Conditional update works (If the Attributes is part of root object).
I have the following model created.
Person with a lot of attributes. The following works:
Expression expr = new Expression();
expr.ExpressionStatement = "Age = :age";
expr.ExpressionAttributeValues[":age"] = 26;
UpdateItemOperationConfig config = new UpdateItemOperationConfig
{
ConditionalExpression = expr,
ReturnValues = ReturnValues.AllNewAttributes
};
Document updatedPerson2 = personCatalog.UpdateItem(doc, config);
But what if my condition was on the Pet Name?
I have tried a couple of approaches with no luck eg:
expr.ExpressionStatement = "Pet.Name = :name";
expr.ExpressionAttributeValues[":name"] = "Lilleper";
Hope someone can help :) Or just nudge me in the right direction.
Upvotes: 1
Views: 1891
Reputation: 5195
Try externalizing the Name sub-attribute name to ExpressionAttributeNames.
Expression expr = new Expression();
expr.ExpressionStatement = "Pet.#name = :name";
expr.ExpressionAttributeNames["#name"] = "Name";
expr.ExpressionAttributeValues[":name"] = "Lilleper";
Upvotes: 2