1

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)));
Jon
  • 377
  • 2
  • 11

1 Answers1

2

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));
Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
  • That returns NotSupportedException unfortunately – Jon Feb 14 '18 at 18:54
  • 1
    ` .Where(j => j.Categories.In(categories));` should work – Ayende Rahien Feb 18 '18 at 21:52
  • @AyendeRahien That too returns a NotSupportedException – Jon Feb 20 '18 at 07:14
  • What is the full error? And what build are you using? – Ayende Rahien Feb 21 '18 at 08:22
  • 1
    @AyendeRahien Ah, the In extension method from Z.Extensions was taking preference over your one from RavenQueryableExtensions! Removed the reference to Z.Extensions and all is working as expected. Thanks for your help, much appreciated. As is RavenDB, the best doc DB out there IMHO. – Jon Feb 23 '18 at 07:40
  • Glad you got it working, Jon! (And perhaps Z.Extensions was taking preference over the .ContainsAny call as well? That code was working for me.) – Judah Gabriel Himango Feb 23 '18 at 16:58
  • 1
    @JudahHimango It was indeed. Looking deeper, because Z.Extensions doesn't use a namespace, it's methods are available everywhere and take precedence over similarly named methods :( Will raise with the developer. Thanks for the help! – Jon Feb 24 '18 at 15:32