RavenDB:如何使用多个搜索词进行查询
我的实体是:
class Resource
{
string Name;
string EmployeeId;
}
如何查询多个员工的资源?我尝试了这个:
Resource[] FindResourcesByEmployees(string[] employeeIds)
{
return this.Session.Query<Resource>()
.Where(r => employeeIds.Contains(r.EmployeeId))
.ToArray();
}
但是,这给了我 NotSupportedException:不支持方法:包含。然后我尝试了以下方法:
Resource[] FindResourcesByEmployees(string[] employeeIds)
{
return this.Session.Query<Resource>()
.Where(r => employeeIds.Any(v => v == r.EmployeeId))
.ToArray();
}
抛出 NotSupportedException:不支持表达式类型:System.Linq.Expressions.TypedParameterException。
在 SQL 中,它会类似于:
SELECT * FROM resource WHERE employeeid IN (1, 2, 3)
我的问题是,如何在 RavenDB 中执行此查询?
My entity is:
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();
}
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();
}
That throws NotSupportedException: Expression type not supported: System.Linq.Expressions.TypedParameterException.
In SQL it would be something like:
SELECT * FROM resource WHERE employeeid IN (1, 2, 3)
My question is, how do I perform this query in RavenDB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
In
运算符。如果我没记错的话你的代码应该是这样的:You can use the
In
operator. If I remember correctly your code should look like this: