使用mongodb-csharp驱动程序(https://github.com/mongodb/mongo-csharp-driver(
我有以下课程&枚举:
public enum PropertyType {
Unknown,
Age,
Weight,
Gender
}
public class Data {
public Dictionary<PropertyType, Int32> Props {get;set;}
}
我可以阅读并保存看起来像这样的数据。
{
Props: {
1: 28,
2: 220,
3: 0
}
}
我无法做的是用props [propertyType.age] == 28查询"数据"。参见下文代码:
var data = from d in collection where d.Props[PropertyType.Age] == 28 select d;
我遇到的错误是:
system.invalidoperationException:'data.props.get_item(propertyType.age(不支持。'
帮助我obiwan kenobi您是我唯一的希望。
您是否尝试过
var data = from d in collection where d.Props.Any(x => x.Key.Equals(PropertyType.Age) && x.Value == 28) select d;