Reputation: 5814
The DynamoDB .NET mapping SDK will not persist an empty list to the table. In practice, this means that removing the last time from a list and attempting to save the item to the table will result in the attribute being unchanged (still has the last item). How can I properly update the attribute to an empty list?
Here's the relevant portion of the mapping class:
[DynamoDBTable("x.y.groups")]
public class Group : GroupListItem
{
public List<string> tokens { get; set; }
}
Here's the code that updates that field:
group.tokens = group.accounts.Select(a => a.token).ToList();
await Context.SaveAsync(group);
If group.accounts is empty (removed the last item), even though group.tokens is an empty list, the attribute in the DynamoDB table will NOT be updated and will still have the one item in the list.
Upvotes: 0
Views: 288
Reputation: 5814
This seems to be a bug in the mapping SDK. In order to work around this bug, I added the if statement below:
group.tokens = group.accounts.Select(a => a.token).ToList();
if (group.tokens.Count == 0) group.tokens = null;
await Context.SaveAsync(group);
This will cause the list attribute to be removed and will map to an empty list when the item is read from the table.
Upvotes: 2