.NET SDK Query Predicate builders

Ask about this Page
Copy for LLM
View as Markdown

Create readable and maintainable Query Predicates using the .NET SDK.

The .NET SDK Query Predicate builder offers a fluent, type-safe interface for building Query Predicates.
For each resource with a query endpoint, the request builders provide a WithQuery method. You pass a lambda function that receives the predicate builder. The predicate builder provides a method for each property of the resource as well as all predicate operators.

Example usage

Query Customers by first namecsharp
// Finds all Customers with the first name "Peter"
projectApiRoot.Customers().Get()
    .WithQuery(q => q.FirstName().Is("Peter"));

Equality comparisons

Apply equality comparisonscsharp
// firstName = "Peter"
projectApiRoot.Customers().Get()
    .WithQuery(q => q.FirstName().Is("Peter"));

// firstName != "Peter"
projectApiRoot.Customers().Get()
    .WithQuery(q => q.FirstName().IsNot("Peter"));

// isEmailVerified = false
projectApiRoot.Customers().Get()
    .WithQuery(q => q.IsEmailVerified().Is(false));

// version != 42
projectApiRoot.Customers().Get()
    .WithQuery(q => q.Version().IsNot(42));

Range comparisons

Apply range comparisonscsharp
// version < 42
projectApiRoot.Customers().Get()
    .WithQuery(q => q.Version().IsLessThan(42));

// version > 42
projectApiRoot.Customers().Get()
    .WithQuery(q => q.Version().IsGreaterThan(42));

// version <= 42
projectApiRoot.Customers().Get()
    .WithQuery(q => q.Version().IsLessThanOrEqual(42));

// version >= 42
projectApiRoot.Customers().Get()
    .WithQuery(q => q.Version().IsGreaterThanOrEqual(42));

Logical operators

Use And, Or, and Not to combine or negate predicate expressions.
Combine predicates with logical operatorscsharp
// firstName = "Peter" and version < 42
projectApiRoot.Customers().Get()
    .WithQuery(q => q.FirstName().Is("Peter").And(q.Version().IsLessThan(42)));

// firstName = "Peter" or version < 42
projectApiRoot.Customers().Get()
    .WithQuery(q => q.FirstName().Is("Peter").Or(q.Version().IsLessThan(42)));

// not (firstName = "Peter" and version < 42)
projectApiRoot.Customers().Get()
    .WithQuery(q => q.FirstName().Is("Peter").And(q.Version().IsLessThan(42)).Not());

Collection queries

Use IsIn to check whether a field's value is contained in a set of values. Chain Not to exclude those values.
Query with IsIncsharp
// version in (42, 43, 44)
projectApiRoot.Customers().Get()
    .WithQuery(q => q.Version().IsIn(new[] { 42, 43, 44 }));

// version not in (42, 43, 44)
projectApiRoot.Customers().Get()
    .WithQuery(q => q.Version().IsIn(new[] { 42, 43, 44 }).Not());