我正在运行一个map reduce作业,将结果数据转储到集合中,"products"集合中的元素看起来像这样(结构由Mongo生成,我不知道是否可以控制):
{
"_id" : { "ProductId" : "1:000001", "ProductTitle" : "Some product with ID 1:000001" },
"value" : { "TotalImpressions" : 3, "TotalClicks" : 40 }
}
理想情况下,我希望将每个条目映射到以下扁平对象:
public class Product
{
public string ProductId { get; set; }
public string ProductTitle { get; set; }
public int TotalImpressions { get; set; }
}
显然,这不起作用,因为序列化程序在根级别查找属性"id"和"value",而该类上不存在这些属性。我采用的解决方法是按照它们出现的方式对对象进行建模,例如:
public class ProductRow
{
/* implementation of these objects excluded, but they just reflect the json objects */
public ProductIdentifier Id { get; set; }
public Product value { get; set; }
}
这个映射本来不错,但是有些啰嗦,我想避免所有这些额外的对象。
是否可能配置BSON反序列化器以支持该映射?我已经查看了文档,但没有看到明显的解决方案。
注:由于工作环境的限制,我只能使用.NET 3.5,请在考虑答案时记住这一点。