我正在尝试使用ElemMatch在MongoDB中查找文档,但是使用2.2驱动程序没有成功。 我收到了如下异常:
System.InvalidOperationException:字段“EnabledForProduct”的序列化器必须实现IBsonArraySerializer并提供项序列化信息。
这是我的类的样子:
public class Document
{
public string Id {get; set;}
public Dictionary<Product, bool> EnabledForProduct { get; set; }
}
public enum Product {Product1,Product2};
我的ClassMap如下:
BsonClassMap.RegisterClassMap<Document>(cm =>
{
cm.AutoMap();
cm.MapMember(c => c.EnabledForProduct)
.SetSerializer(new DictionaryInterfaceImplementerSerializer<Dictionary<Product, bool>>(DictionaryRepresentation.ArrayOfDocuments,
BsonSerializer.LookupSerializer<int>(),
BsonSerializer.LookupSerializer<bool>()));
});
异常情况发生在尝试使用过滤器(Filter)时,例如:
Builders<Document>.Filter.ElemMatch(f => f.EnabledForProduct,
x => x.Key == Product1 && x.Value))
在1.x驱动程序中,这个功能曾经完美运行。
有人知道我做错了什么吗?