DorR
DorR

Reputation: 645

ravendb check if item is in list

How can I query RavenDB for all "Products" which are in a list of categories?

Lets say I want all products that their category is "1" or "2" or "3". The list of categories(1,2,3) should by dynamic. it will change based on user input.

Upvotes: 0

Views: 90

Answers (1)

Shawn C.
Shawn C.

Reputation: 6841

If a product can only have one category then it would something like this:

products = from p in session.Query<Product>()
        where p.Category.In(new[] { 1,2,3 })
        select p;

If multiple categories for a product the following should work:

products = from p in session.Query<Product>()
        where p.Categories.Any(new[] { 1,2,3 })
        select p;

Upvotes: 2

Related Questions