Skip to main content

Starts-With Query

StartsWith

List<Product> products = session
.Query<Product>()
// Call 'StartsWith' on the field
// Pass the prefix to search by
.Where(x => x.Name.StartsWith("Ch"))
.ToList();

// Results will contain only Product documents having a 'Name' field
// that starts with any case variation of 'ch'

StartsWith (case-sensitive)

List<Product> products = session
.Query<Product>()
// Pass 'exact: true' to search for an EXACT prefix match
.Where(x => x.Name.StartsWith("Ch"), exact: true)
.ToList();

// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'

Negate StartsWith

List<Product> products = session
.Query<Product>()
// Call 'StartsWith' on the field
// Pass the prefix to search by
.Where(x => x.Name.StartsWith("Ch") == false)
.ToList();

// Results will contain only Product documents having a 'Name' field
// that does NOT start with 'ch' or any other case variations of it