flukus
flukus

Reputation: 1028

Ravendb - multiple where clauses?

Is it possible to add multiple where clauses after a query is created. Eg, The following query correctly returns 1 result:

var q1 = session.Query<Template>()
    .Where(x => x.Tags.Any(y => y == "one"))
    .Where(x => x.Tags.Any(y => y == " two"));
var r1 = q1.ToList();

But this one behaves as if there is no where condition and returns 30 results:

var q2 = session.Query<Template>();
q2.Where(x => x.Tags.Any(y => y == "one"));
q2.Where(x => x.Tags.Any(y => y == " two"));
var r2 = q2.ToList();

Is the second example at all supported by ravendb? And why arn't the two queries equivalent?

Upvotes: 0

Views: 778

Answers (1)

Thomas Freudenberg
Thomas Freudenberg

Reputation: 5078

They are not the same because you don't use the combined queries. You have to change your code like this:

var q2 = session.Query<Template>();
q2 = q2.Where(x => x.Tags.Any(y => y == "one"));
q2 = q2.Where(x => x.Tags.Any(y => y == " two"));
var r2 = q2.ToList();

Upvotes: 7

Related Questions