Search code examples
c#linqravendbravendb4

Find the intersection of two lists using the RavenDB 4 LINQ provider


How can you query RavenDB 4 to find documents which have a list of documents matching items from a input list?

The following used to work in RavenDB 3 but isn't supported in 4:

List<string> categories = new List<string>() { "C#", "java" });   
var jobs = _session.Query<Job, Job_Index>.Where(j => j.Categories.Any(c => c.In(categories)));

Solution

  • I believe something like this should work:

    using Raven.Client.Documents.Linq; // needed for .ContainsAny extension method
    
    var categories = new List<string>() { "C#", "java" });   
    var jobs = _session.Query<Job, Job_Index>
         .Where(j => j.Categories.ContainsAny(categories));