【发布时间】:2016-09-20 20:24:42
【问题描述】:
我使用 mongodb [BsonExtraElements] 功能来扩展我的类一些动态数据,但不幸的是我无法通过 mongodb C# 驱动程序创建查询。
这是我的模型类:
public class MongoProductEntity
{
public MongoProductEntity()
{
AdditionalColumns = new BsonDocument { AllowDuplicateNames = false };
}
[BsonExtraElements]
public BsonDocument AdditionalColumns { get; set; }
public string BrandName { get; set; }
}
这里是查询部分:
var productEntity = new MongoProductEntity ()
{
BrandName = "Brand"
};
productEntity.AdditionalColumns.Add("testProperty", 6);
productEntity.AdditionalColumns.Add("testProperty2", "almafa");
await productEntityRepo.InsertAsync(productEntity);
var qq = productEntityRepo.Where(x => x.AdditionalColumns["testProperty"] == 6).ToList();
此查询不返回数据库中的任何元素,但是如果我尝试查询 BrandName 属性,一切正常!
有没有人遇到过类似的情况或知道为什么该查询不起作用? 提前谢谢!
这里只是一个简短的说明:productEntityRepo 的类型是 MongoDb MongoProductEntity 集合的包装器,这个包装器将集合返回为 Queryable,仅此而已。我使用的是 MongoDb 3.2.9,最新的 C# Driver 2.2.4。
【问题讨论】:
标签: c# .net mongodb mongodb-query