Repository navigation
Mise Filtering
Where adds a predicate to a SELECT statement. Repeated calls combine with AND. Runtime values in predicates remain database parameters.
var query = new PostgreSqlQueryBuilder()
.Select($"{CourseTbl.CourseIdCol:raw}")
.Select($"{CourseTbl.TitleCol:raw}")
.Select($"{CourseTbl.CapacityCol:raw}")
.From($"{CourseTbl.Table:raw}")
.Where($"{CourseTbl.CapacityCol:raw} >= {minimumCapacity}")
.Where(
$"({CourseTbl.TitleCol:raw} LIKE {prefix + "%"} OR {CourseTbl.CampusIdCol:raw} IS NULL)"
);Parentheses keep the OR condition together when the builder joins predicates with AND. Write the grouping you intend; the builder does not infer boolean grouping from your application logic.
Use SQL IS NULL and IS NOT NULL for missing values. Normal parameter interpolation does not change SQL null semantics. See SQL interpolation.
int[] selectedIds = [10, 20, 30];
query.WhereIn($"{CourseTbl.CourseIdCol:raw}", selectedIds);WhereIn binds each list item separately. It accepts an IReadOnlyCollection<T>. An empty list generates a false predicate, 1 = 0, so it returns no matches rather than emitting invalid IN () syntax.
For a very large list, account for your database's parameter limit. The builder does not turn the collection into a temporary table or provider-specific array automatically. A subquery can be a better source when those IDs already live in the database.
var largeCampuses = new PostgreSqlQueryBuilder()
.Select($"{CourseTbl.CampusIdCol:raw}")
.From($"{CourseTbl.Table:raw}")
.Where($"{CourseTbl.CapacityCol:raw} >= {100}");
query.WhereIn($"{CourseTbl.CampusIdCol:raw}", largeCampuses);The child must project a value compatible with the left expression. It compiles into the parent SQL and shares its parameter numbering; it is not executed first as a separate database call.
var matchingCampus = new PostgreSqlQueryBuilder()
.Select($"1")
.From($"{CampusTbl.Table:raw}")
.Where($"{CampusTbl.CampusIdCol:raw} = {CourseTbl.CampusIdCol:raw}")
.Where($"{CampusTbl.NameCol:raw} = {campusName}");
query.WhereExists(matchingCampus);This correlated subquery retains courses with a campus matching campusName. EXISTS checks whether the child produces any row, so Select($"1") is sufficient.
See Subqueries for other child-query forms and Aggregation for HAVING predicates after grouping.
- Home
- Getting started
-
Package guides
- Partie
- Expo
-
Mise
- Database setup
- Table mappings
- Aliases
- Relationships
- Result rows
- SQL interpolation
- Queries
- Filtering
- Joins
- Aggregation
- Paging and ordering
- Subqueries
- Set operations
- Common table expressions
- Readers
- Streaming
- Writers
- Inserts
- Updates
- Deletes
- Returned rows
- Custom SQL and procedures
- Transactions
- Resource lifetimes
- Database dialects
- Diagnostics
- Integrations
- Recipes
- Reference
- Troubleshooting
- Development