【问题标题】:RavenDB (4.0-beta): How to full-text-search dynamic attributesRavenDB (4.0-beta):如何全文​​搜索动态属性
【发布时间】:2017-09-01 08:37:02
【问题描述】:

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

【问题讨论】:

  • 其实是个好问题。我相信在 RavenDB 3.5 之前你可以使用var results = DocumentSession.Advanced.LuceneQuery&lt;Foo&gt;() .Where("Attributes.IsFeatured: true") .ToList();,但由于 LuceneQuery 已被 RQL 弃用,我不知道现在是如何做到的。
  • 仅供参考:Raven 查询语言 (RQL) 不在 Raven 3.5 中。它将在 Raven 4.0 中。

标签: full-text-search ravendb


【解决方案1】:

应该这样做:

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

【讨论】:

  • 我接受这个,但我找不到对DocumentSession.Advanced.DocumentSession 的引用。不过你帮我上路了。经过一番搜索,我发现了这个 await session.Advanced.AsyncDocumentQuery&lt;Foo&gt;().WhereEquals("Attributes.IsFeatured", true) 对我有用。
猜你喜欢
  • 2011-05-17
  • 2019-12-15
  • 1970-01-01
  • 1970-01-01
  • 2012-12-27
  • 2013-03-08
  • 1970-01-01
  • 2012-12-02
  • 1970-01-01
相关资源
最近更新 更多