无法使用MongoDB C#2.0驱动程序查询字典项
作者:互联网
我有一个具有字典属性的类.
[DataMember]
[BsonElement("QueriableParameters")]
public Dictionary<string, string> QueriableParameters
{
get;
set;
}
我正在使用新的MongoDB c#2.0驱动程序,但似乎无法做到这一点:
var selectQuery1 = await collection.Find(s => s.QueriableParameters["UniqueLoanNumber"] == "3049793b-91eb-49d8-a5b4-7cbfd1a1bb3c").ToListAsync();
我收到此错误说明:
InnerException: System.InvalidOperationException
HResult=-2146233079
Message=s.QueriableParameters.get_Item("UniqueLoanNumber") is not supported.
Source=MongoDB.Driver
StackTrace:
at MongoDB.Driver.Linq.Translators.PredicateTranslator.GetSerializationInfo(Expression expression)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.BuildComparisonQuery(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
请帮我指出正确的方向.
谢谢,
解决方法:
谢谢Craig提供的信息.
我想现在唯一的方法是:
var builders = Builders<NotificationData>.Filter;
var filter = builders.Eq("QueriableParameters.UniqueLoanNumber", "theIdLookingfor");
var selectQuery = await collection.Find(filter).ToListAsync();
标签:mongodb,mongodb-net-driver,mongodb-csharp-2-0,c 来源: https://codeday.me/bug/20191120/2044439.html