RavenDB: How to query with multiple search terms

会有一股神秘感。 提交于 2019-11-28 23:48:16

问题


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?


回答1:


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();
}


来源:https://stackoverflow.com/questions/7899936/ravendb-how-to-query-with-multiple-search-terms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!