【发布时间】:2012-10-31 17:10:20
【问题描述】:
我在 DynamoDB 中保存用户配置文件,并使用属性将 .net 类型转换为 dynamo 条目
所以这是我正在使用的转换器:
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;
}
}
现在的问题是,当字典为空并且ToEntry 返回一个空的PrimitiveList 时,不会保存此字典的更改
所以如果我这样做:
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;
【问题讨论】:
标签: .net amazon-web-services amazon amazon-dynamodb