user3228992
user3228992

Reputation: 1373

RavenDb: Check if List<string> contains Any in another List<string>

I trying to query on two list<string> in a ravendb-query to se if list-B contains any of the values is list A.

But a get the error: Can't extract value from expression of type: Parameter.

Here is my attempt:

public class Media
{
    public List<string> Directors
}

var anotherMedia = new Media() {Directors = new List<string>() {"A", "B", "C"}};


var mediaWithSameDirector = session.Query<Media, Media_Index>().
Where(o => o.Directors.Any(l1 => anotherMedia.Any(l2 => l1 == l2)))
.Take(10).ToList();

Upvotes: 2

Views: 794

Answers (1)

Ayende Rahien
Ayende Rahien

Reputation: 22956

You can use In for this:

var mediaWithSameDirector = session.Query<Media, Media_Index>()
     .Where(o => o.Directors.In(anotherMedia)
     .Take(10) 
     .ToList();

Upvotes: 4

Related Questions