DynamicWhere.ex
DynamicWhere.exv3.2.0·docs

Segment

A Segment stitches together multiple ConditionSet objects with Union / Intersect / Except set operations, then applies optional sort and pagination. A projection, if you give one, is applied after they are combined, to the ordered and paged rows.

Properties

PropertyTypeDescription
ConditionSetsList<ConditionSet>Ordered condition sets.
SelectsList<string>?Optional field projection, applied last to the combined, ordered and paged rows, as for a Filter.
OrdersList<OrderBy>?Optional sort criteria.
PagePageBy?Optional pagination.
Async-only
The condition sets are combined into one query that the database answers: Union and Intersect join the sets' conditions, and Except removes its set's rows by primary key. A type with no primary key uses SQL UNION / INTERSECT / EXCEPT. Segments are executed exclusively through ToListAsync<T>(Segment). 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.ToListAsync(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