Syntax
Table Of Contents
The Query Class
The Query class allows you to craft from the simplest to the most complex queries.
You can then pass your instance of the Query class to one of the many available methods in the repository for the query to be applied to operations like Retrieve, Update, Delete.
It is a generic class that takes a Property Enum as a generic type parameter.
Property Enum
When The Sharp Factory App generates the C# code in your solution, amongst other things, it generates a collection of enumerations that represent all the properties of each entity.
The naming convention is EntityName + Property. For example an Entity called Customer will have a corresponding enum called CustomerProperty.
Query Instance
Start by creating an instance of the Query class passing the Property Enum as generic type parameter like so:
Pass that instance to one of the repository methods available on that Entity's repository like this:
Anatomy of a Query
A Query is composed of multiple parts or sections.
-
Predicate: Here you specify all the where clauses.
-
Sorting: Here you specify all the sorting criteria.
-
Navigation Properties: Here you specify all the related entities to include in the result.
-
Pagination: Here you specify the pagination criteria to apply to the query.
The different parts of the query are optional.
Fluent Syntax
The following example demonstrates how to build the query "skeleton" using Fluent Syntax.
This means concatenating conditions in a single statement.
Builder Syntax
The following example demonstrates how to build the query "skeleton" using Builder Syntax.
This means concatenating conditions using delegates.
Builder syntax can make it easier to dynamically craft queries for more complex scenarios.
Builder Syntax vs Fluent Syntax
They both produce equivalent SQL Queries.
Choosing one or the other is a matter of taste.
We recommend you experiment with both and find the best option for your use case.
For more information on how to craft queries and use filtering see the Filtering section of the documentation.