DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

Segment

A Segment stitches together multiple ConditionSet objects with Union / Intersect / Except set operations, then applies optional projection, sort, and pagination.

Properties

PropertyTypeDescription
ConditionSetsList<ConditionSet>Ordered condition sets.
SelectsList<string>?Optional field projection.
OrdersList<OrderBy>?Optional sort criteria.
PagePageBy?Optional pagination.
Async-only
Segments compile to set-operation SQL (UNION / INTERSECT / EXCEPT) and are executed exclusively through ToListAsyncSegment. There is no synchronous counterpart.

C# example

var segment = new Segment
{
    ConditionSets = new List<ConditionSet>
    {
        new ConditionSet
        {
            Sort = 0,
            ConditionGroup = new ConditionGroup
            {
                Connector = Connector.And,
                Conditions = new List<Condition>
                {
                    new Condition
                    {
                        Sort = 1, Field = "Country",
                        DataType = DataType.Text, Operator = Operator.Equal,
                        Values = new List<object> { "IQ" }
                    }
                }
            }
        },
        new ConditionSet
        {
            Sort = 1,
            Intersection = Intersection.Except,
            ConditionGroup = new ConditionGroup
            {
                Connector = Connector.And,
                Conditions = new List<Condition>
                {
                    new Condition
                    {
                        Sort = 1, Field = "IsBlocked",
                        DataType = DataType.Boolean, Operator = Operator.Equal,
                        Values = new List<object> { true }
                    }
                }
            }
        }
    },
    Orders = new List<OrderBy>
    {
        new OrderBy { Sort = 1, Field = "Name" }
    },
    Page = new PageBy { PageNumber = 1, PageSize = 50 }
};

SegmentResult<Customer> result = await dbContext.Customers.ToListAsyncSegment(segment);

JSON example

{
  "conditionSets": [
    {
      "sort": 0,
      "intersection": null,
      "conditionGroup": {
        "connector": "And",
        "conditions": [
          { "sort": 1, "field": "Country", "dataType": "Text", "operator": "Equal", "values": ["IQ"] }
        ],
        "subConditionGroups": []
      }
    },
    {
      "sort": 1,
      "intersection": "Except",
      "conditionGroup": {
        "connector": "And",
        "conditions": [
          { "sort": 1, "field": "IsBlocked", "dataType": "Boolean", "operator": "Equal", "values": [true] }
        ],
        "subConditionGroups": []
      }
    }
  ],
  "orders": [
    { "sort": 1, "field": "Name", "direction": "Ascending" }
  ],
  "page": { "pageNumber": 1, "pageSize": 50 }
}

See also