RavenDB:如何使用多个搜索词进行查询 [英] RavenDB: How to query with multiple search terms
问题描述
我的实体是:
class Resource
{
string Name;
string EmployeeId;
}
如何查询多个员工的资源?我试过这个:
How do I query for resources of multiple employees? I tried this:
Resource[] FindResourcesByEmployees(string[] employeeIds)
{
return this.Session.Query<Resource>()
.Where(r => employeeIds.Contains(r.EmployeeId))
.ToArray();
}
但是,这给了我 NotSupportedException:不支持的方法:包含.然后我尝试了以下方法:
However that gives me NotSupportedException: Method not supported: Contains. Then I tried the following method:
Resource[] FindResourcesByEmployees(string[] employeeIds)
{
return this.Session.Query<Resource>()
.Where(r => employeeIds.Any(v => v == r.EmployeeId))
.ToArray();
}
抛出 NotSupportedException: Expression type not supported: System.Linq.Expressions.TypedParameterException.
That throws NotSupportedException: Expression type not supported: System.Linq.Expressions.TypedParameterException.
在 SQL 中,它类似于:
In SQL it would be something like:
SELECT * FROM resource WHERE employeeid IN (1, 2, 3)
我的问题是,如何在 RavenDB 中执行此查询?
My question is, how do I perform this query in RavenDB?
推荐答案
您可以使用 In
运算符.如果我没记错的话,你的代码应该是这样的:
You can use the In
operator. If I remember correctly your code should look like this:
using Raven.Client.Linq;
Resource[] FindResourcesByEmployees(string[] employeeIds)
{
return this.Session.Query<Resource>()
.Where(r => r.EmployeeId.In<string>(employeeIds)))
.ToArray();
}
这篇关于RavenDB:如何使用多个搜索词进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!