You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: Querying: How to Query With Exact Match

By default, the Where method in Query uses a case-insensitive match.

To perform a case-sensitive match you should use the exact parameter.

Syntax

IRavenQueryable<T> Where<T>(Expression<Func<T, int, bool>> predicate, bool exact);

IRavenQueryable<T> Where<T>(Expression<Func<T, bool>> predicate, bool exact);

Parameters
predicate Expression<Func<T, int, bool>> Predicate with match condition
exact bool Indicates if predicate should be matched in case-sensitive manner

Example I - Query With Exact Match

// load all entities from 'Employees' collection
// where FirstName equals 'Robert' (case sensitive match)
List<Employee> employees = session
    .Query<Employee>()
    .Where(x => x.FirstName == "Robert", exact: true)
    .ToList();
// load all entities from 'Employees' collection
// where FirstName equals 'Robert' (case sensitive match)
List<Employee> employees = await asyncSession
    .Query<Employee>()
    .Where(x => x.FirstName == "Robert", exact: true)
    .ToListAsync();
from Employees where exact(FirstName == 'Robert')

Example II - Query With Inner Exact Match

// return all entities from 'Orders' collection
// which contain at least one order line with
// 'Singaporean Hokkien Fried Mee' product
// perform a case-sensitive match
List<Order> orders = session
    .Query<Order>()
    .Where(x => x.Lines.Any(p => p.ProductName == "Singaporean Hokkien Fried Mee"), exact: true)
    .ToList();
// return all entities from 'Orders' collection
// which contain at least one order line with
// 'Singaporean Hokkien Fried Mee' product
// perform a case-sensitive match
List<Order> orders = await asyncSession
    .Query<Order>()
    .Where(x => x.Lines.Any(p => p.ProductName == "Singaporean Hokkien Fried Mee"), exact: true)
    .ToListAsync();
from Orders 
where exact(Lines[].ProductName == 'Singaporean Hokkien Fried Mee')