我试图避免使用魔术字符串,但我无法找到解决方案。 我有两个对象:
public class Class1
{
public BsonObjectId id { get; set; }
//...
public List<Class2> class2List = new List<FormerJob>();
}
public class Class2
{
public string property{ get; set; }
//...
}
在我的代码中:
var keys = Builders<Class1>.IndexKeys.Text("class2List.property")
textIndex = mongoCollection.Indexes.CreateOneAsync(keys, options));
显然以下代码在代码中不起作用:
var keys = Builders<Class1>.IndexKeys.Text(p => p.class2List.property)
因为class2List是Class2的List
我试图避免使用“class2List.property”:
var keys = Builders<Class1>.IndexKeys.Text(p => p.class2[0].property)
但它会在Mongo中生成textindex,如: class2List.0.property 而不是: class2List.property
如何使用lambdas创建此textindex?