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

Tom*_*ers 3 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"    
}
Run Code Online (Sandbox Code Playgroud)

这是我试图使用的查询.

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);
Run Code Online (Sandbox Code Playgroud)

遗憾的是,我甚至无法编译此代码,因为我收到编译错误(Error: An expression tree may not contain a dynamic operation).
我不认为这是一种在动态属性中搜索(使用ravendb)的好方法.有更好的方法吗?

Aye*_*ien 5

这应该这样做:

DocumentSession.Advanced.DocumentSession<Foo>()
  .WhereEquals("Attributes.IsFeatured", true)
  .ToList()
Run Code Online (Sandbox Code Playgroud)