Filtering

Table Of Contents

Query Instance

Start by creating an instance of the Query class passing the Property Enum as generic type parameter like so:

C#
// create an instance and 

// specify the entity's PropertyEnum

var query = new Query<CustomerProperty>();

Pass that instance to one of the repository methods available on that Entity's repository like this:

C#
// create an instance of the Repository Container

// remember this can be a singleton if you

// declare it early on and reuse it for the

// lifetime of your application

var repo = new RepositoryContainer();

// create an instance of Query and 

// specify the entity's PropertyEnum

var query = new Query<CustomerProperty>();

// pass the query to one of the repository methods

// in this case the ToList on the Customer repository

var result = repo.AppDb.Sales.Customer.ToList(query);

Examples

For example if we wanted to say "All customers where the balance is greater than zero":

Fluent Syntax

C#
// create an instance and

// specify the entity's PropertyEnum

var query = new Query<CustomerProperty>()
    .BeginPredicate()
        .Where(CustomerProperty.Balance).GreaterThan(0)
    .EndPredicate();

Builder Syntax

C#
// create an instance and

// specify the entity's PropertyEnum

var query = new Query<CustomerProperty>()
    .Builder(builder =>
    {
        builder
        .Predicate((builder) =>
        {
            builder.Where(CustomerProperty.Balance).GreaterThan(0);
        });
    });
    

And Or Logical Operators

You can further craft your query by appending more conditions using the Where( means And ) or the Or operators.

Let's build on our previous example. "All customers where the balance is greater than 1000 or less than 500".

Fluent Syntax

C#
// create an instance and 

// specify the entity's PropertyEnum

var query = new Query<CustomerProperty>()
    .BeginPredicate()
        .Where(CustomerProperty.Balance).GreaterThan(1000)
        .Or(CustomerProperty.Balance).LessThan(500)
    .EndPredicate();

Builder Syntax

C#
// create an instance and

// specify the entity's PropertyEnum

var query = new Query<CustomerProperty>()
    .Builder(builder =>
    {
        builder
        .Predicate((builder) =>
        {
            builder
            .Where(CustomerProperty.Balance).GreaterThan(0)
            .Or(CustomerProperty.Balance).LessThan(500);
        });
    });
    

The Or operator works in the same way that the And(Where) operator. Just replace the word Where for Or.

Supported Conditions

For a comprehensive list of supported conditions please read the Conditions documentation.

Complex Expressions

In some circumstances you might want to group conditions into more elaborate expressions in which these conditions might be evaluated together.

For more information on how to craft these types of queries please go to the Complex Expressions section of the documentation.