我想用RavenDb 4.0.0-beta-40018查询包含动态属性的实体,但不知道如何去做。RavenDB(4.0-beta):如何全文搜索动态属性
class Foo {
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public string Name { get; set; }
public dynamic Attributes { get; set; }
}
{
"Attributes": {
"IsFeatured": true
},
"CreatedAt": "2017-08-30T15:53:21.1881668Z",
"Name": "Featured Foo"
}
这是我试过使用的查询。
const string propertyName = "IsFeatured";
var results = session.Query<Foo>()
.Where(x => x.Attributes != null)
.Where(x => x.Attributes[propertyName] != null)
.Where(x => x.Attributes[propertyName] == true);
可悲的是,我甚至不能因为我得到一个编译错误(Error: An expression tree may not contain a dynamic operation
)编译的代码。
我不认为这是在动态属性中搜索(使用ravendb)的好方法。有更好的方法吗?
其实一个很好的问题。我相信,直到RavenDB 3.5,你可以使用'var results = DocumentSession.Advanced.LuceneQuery() 。Where(“Attributes.IsFeatured:true”) .ToList();',但是由于LuceneQuery被弃用而倾向于RQL我不知道现在如何做到这一点。 –
仅供参考:乌鸦查询语言(RQL)不在乌鸦3.5中。它将在Raven 4.0中。 –