You are currently browsing legacy 3.0 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 use NOT operator?

IDocumentQuery contains NOT operator which can be used to negate next predicate

Note

NOT operator cannot be used alone without succeeding predicate.

Example I

// load up to 128 entities from 'Employees' collection
// where FirstName NOT equals 'Robert'
List<Employee> employees = session
	.Advanced
	.DocumentQuery<Employee>()
	.Not
	.WhereEquals(x => x.FirstName, "Robert")
	.ToList();

Example II

// load up to 128 entities from 'Employees' collection
// where FirstName NOT equals 'Robert'
// and LastName NOT equals 'King'
List<Employee> employees = session
	.Advanced
	.DocumentQuery<Employee>()
	.Not
	.OpenSubclause()
	.WhereEquals(x => x.FirstName, "Robert")
	.AndAlso()
	.WhereEquals(x => x.LastName, "King")
	.CloseSubclause()
	.ToList();