1

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.

enter image description here

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.

1
  • Strange. If I cange it to: expr.ExpressionStatement = "Pet.Age = :age"; expr.ExpressionAttributeValues[":age"] = 30; it works? Doesn't string work? Commented Jan 27, 2017 at 6:36

1 Answer 1

2

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";
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome :) Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.