DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

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

ValueDescriptionSQL equivalent
UnionCombines both sets — every item from either side.UNION
IntersectKeeps only items present in both sets.INTERSECT
ExceptRemoves 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: ElectronicsPrice < 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 20

C# 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);