ravendb 中的多个嵌套 where 子句

Multiple nested where clauses in ravendb

我正在尝试将此查询从 EF 迁移到 ravendb

DateTime interval;
IList<string> excludedUserNames;

return this.ravenSession.Query<User>()
    .Where(u => 
        u.NotifyOnNewForumPost 
        && (u.LastForumsNotification < u.LastVisit || u.LastForumsNotification < interval))
    .Select(u => u.Email)
    .ToList();

使用Query似乎无法表达嵌套子句,所以我查看了DocumentQuery,但显然lucene不支持比较文档中的两个值。

我是否遗漏了文档中的某些内容(它似乎只处理简单的过滤?!),或者是否有其他方法(除了在内存中过滤)?

Raven 不支持 .Contains(u.UserName)。您也许可以使用 .In(...) 代替:

return this.ravenSession.Query<User>()
    .Where(u => 
        u.NotifyOnNewForumPost 
        && (u.LastForumsNotification < u.LastVisit || u.LastForumsNotification < interval) 
        && !u.UserName.In(excludedUserNames))
    .Select(u => u.Email)
    .ToList();

希望对您有所帮助!

您不能在查询期间比较 RavenDB 中的两个值。您不能这样做的原因是这需要数据库引擎扫描所有文档以找到匹配项。 相反,创建一个在索引时进行比较的索引,并查询结果。