Intersection
Intersection is the set operation applied between consecutive ConditionSet results inside a Segment. The sets are combined into one query the database answers. Union and Intersect combine the sets' own conditions, and only Except matches rows, by primary key.
Values
| Value | Description | Generated as |
|---|---|---|
Union | Combines both sets — every row from either side, once. | OR of the sets' conditions |
Intersect | Keeps only rows present in both sets. | AND of the sets' conditions |
Except | Removes rows found in the second set from the first. | NOT EXISTS on the primary key |
Warning
A type with no primary key has no row identity to match on, so its sets use SQL
UNION / INTERSECT / EXCEPT instead. Those compare whole rows: identical rows collapse into one, and a column the database cannot compare, such as PostgreSQL json, fails the query even when it is not selected.Ordering and the first set
Sets execute in Sort order. The Intersection on the first set (lowest Sort) is ignored — there is nothing to combine it with. Sets at index 1+ must have an Intersection, otherwise validation throws RequiredIntersection.
Warning
Set operations are async-only. The only entry point is
.ToListAsync<T>(Segment). Sets combine left to right: ((set1 op2 set2) op3 set3).JSON example — Union then Except
Three sets: Electronics ∪ Price < 20 ∖ Inactive.
{
"conditionSets": [
{
"sort": 1,
"intersection": null,
"conditionGroup": {
"connector": "And",
"conditions": [
{ "sort": 1, "field": "Category.Name", "dataType": "Text", "operator": "Equal", "values": ["Electronics"] }
],
"subConditionGroups": []
}
},
{
"sort": 2,
"intersection": "Union",
"conditionGroup": {
"connector": "And",
"conditions": [
{ "sort": 1, "field": "Price", "dataType": "Number", "operator": "LessThan", "values": [20] }
],
"subConditionGroups": []
}
},
{
"sort": 3,
"intersection": "Except",
"conditionGroup": {
"connector": "And",
"conditions": [
{ "sort": 1, "field": "IsActive", "dataType": "Boolean", "operator": "Equal", "values": [false] }
],
"subConditionGroups": []
}
}
],
"orders": [ { "sort": 1, "field": "Name", "direction": "Ascending" } ],
"page": { "pageNumber": 1, "pageSize": 20 }
}Logic:
(Electronics) UNION (Price < 20) EXCEPT (Inactive)
→ order by Name ASC
→ page 1, size 20C# usage
using DynamicWhere.ex.Enums;
var segment = new Segment
{
ConditionSets = new List<ConditionSet>
{
new ConditionSet { Sort = 1, Intersection = null, ConditionGroup = setA },
new ConditionSet { Sort = 2, Intersection = Intersection.Union, ConditionGroup = setB },
new ConditionSet { Sort = 3, Intersection = Intersection.Except, ConditionGroup = setC },
}
};
SegmentResult<Product> result = await db.Products.ToListAsync(segment);Related
- Segment → the wrapper class that holds the condition sets.
- ConditionSet → a single member of the set.
- .ToListAsync(Segment) → the only extension that executes segments.
- Segment example → end-to-end JSON cookbook.