I’m saving user profiles in DynamoDB, and using attributes for converting the .net types to dynamo entries
so this is a converter that I’m using:
public class DictRoomClassHouseInfoConverter : IPropertyConverter
{
...
public DynamoDBEntry ToEntry(object value)
{
var dictionary = value as Dictionary<RoomClass, HouseInfo>;
if (dictionary == null)
{
throw new ArgumentException("Invalid type");
}
var entry = new PrimitiveList();
foreach (var kvp in dictionary)
{
entry.Add(new Primitive { Value = string.Format("{0}|{1}|{2}", (int)kvp.Key, kvp.Value.House, kvp.Value.TimesSold) });
}
return entry;
}
}
now the problem is that when the Dictionary is empty and an empty PrimitiveList is returned by ToEntry, the changes for this Dictionary won’t be saved
so if I do something like:
var profile = GetProfile(id);
//profile.DictProp has 3 items;
profile.DictProp.Clear();
//profile.DictProp has 0 items;
SaveProfile(profile);
var p = GetProfile(id);
//profile.DictProp has 3 items;
@jtlebi answered correctly that the service does not accept empty strings or empty sets. The .NET SDK builds on this, in that if you try to save an empty PrimitiveList, the SDK will ignore this and the attribute will not change.
However, there is still a way to remove an attribute: set the field on the .NET object to null or return null from the IPropertyConverter.ToEntry method. Then, when you call DynamoDBContext.Save, the SDK will issue a DELETE command for that particular attribute.