Intersection
Intersection is the set operation applied between consecutive ConditionSet results inside a Segment. It maps onto LINQ's Union / Intersect / Except and the matching SQL set operators.
Values
| Value | Description | SQL equivalent |
|---|---|---|
Union | Combines both sets — every item from either side. | UNION |
Intersect | Keeps only items present in both sets. | INTERSECT |
Except | Removes items found in the second set from the first. | EXCEPT |
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). Each set is materialized independently in memory before the operation is applied.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.