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?
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With