# .NET SDK Query Predicate builders 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](/api/predicates/query.md). 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 ```csharp title="Query Customers by first name" // Finds all Customers with the first name "Peter" projectApiRoot.Customers().Get() .WithQuery(q => q.FirstName().Is("Peter")); ``` For more examples, see the [query test class](https://github.com/commercetools/commercetools-dotnet-core-sdk-v2/blob/master/commercetools.Sdk/Tests/commercetools.Sdk.Api.Tests/QueryTests.cs) in the SDK repository. ### Equality comparisons ```csharp title="Apply equality comparisons" // 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 ```csharp title="Apply range comparisons" // 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. ```csharp title="Combine predicates with logical operators" // 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. ```csharp title="Query with IsIn" // 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()); ``` ## Related pages - [Area overview page with navigation](/dev-tooling.md) - [Previous page: Get started](/dev-tooling/dotnet-sdk-getting-started.md) - [Search documentation and API specs](/search.md)