RavenDB(4.0-beta):如何全文​​搜索动态属性

时间:2017-09-01 08:37:02

标签: full-text-search ravendb

我想使用RavenDb 4.0.0-beta-40018查询包含动态属性的实体,但我不确定如何操作。

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)的好方法。有更好的方法吗?

1 个答案:

答案 0 :(得分:5)

这应该这样做:

DocumentSession.Advanced.DocumentSession<Foo>()
  .WhereEquals("Attributes.IsFeatured", true)
  .ToList()