see on GitHub

How to migrate DocumentQuery from 3.x?

There were many changes to DocumentQuery regarding specific functionalities, we encourage you to read about them in their respective articles, but the biggest change that this particular article wants to address is the default operator change.

In previous version of RavenDB there was a disprepancy between Query and DocumentQuery in regards to default operator. The Query was using AND and DocumentQuery was using OR. Now both of those types of query are using the same operator which is AND.

Example I

Retrieve all employees which FirstName is John or Bob by using UsingDefaultOperator method.

3.x 4.0
List<Employee> results = session
    .Advanced
    .DocumentQuery<Employee>()
    .WhereEquals(x => x.FirstName, "John")
    .WhereEquals(x => x.FirstName, "Bob")
    .ToList();
List<Employee> results = session
    .Advanced
    .DocumentQuery<Employee>()
    .UsingDefaultOperator(QueryOperator.Or)
    .WhereEquals(x => x.FirstName, "John")
    .WhereEquals(x => x.FirstName, "Bob")
    .ToList();

Example II

Retrieve all employees which FirstName is John or Bob using OrElse method.

3.x 4.0
List<Employee> results = session
    .Advanced
    .DocumentQuery<Employee>()
    .WhereEquals(x => x.FirstName, "John")
    .WhereEquals(x => x.FirstName, "Bob")
    .ToList();
List<Employee> results = session
    .Advanced
    .DocumentQuery<Employee>()
    .WhereEquals(x => x.FirstName, "John")
    .OrElse()
    .WhereEquals(x => x.FirstName, "Bob")
    .ToList();