QueryFilter

open class QueryFilter: DataValue

Encapsulates the boolean value of an OData logical operator. Used to wrap the results of logical QueryOperator in a type-safe manner.

See also

DataQuery.queryFilter, DataQuery.filter.

Example using proxy classes

open func queryWithFilterExample() throws -> Void {
    defer {
        DebugConsole.traceOut("example.NorthwindProxyClient.queryWithFilterExample")
    }
    do {
        DebugConsole.traceIn("example.NorthwindProxyClient.queryWithFilterExample")
        do {
            let service = self.service
            let query = DataQuery()
                .select(Customer.customerID, Customer.companyName,
                    Customer.contactName)
                .filter(Customer.country.equal("Germany")
                    .and(Customer.contactName.greaterEqual("N")))
            // Alternate syntax using convenience operators:
            // let query = DataQuery()
            //     .select(Customer.customerID, Customer.companyName, Customer.contactName)
            //     .filter(Customer.country == "Germany" && Customer.contactName >= "N")
            let customers = try service.fetchCustomers(matching: query)
            self.showCustomers(customers)
        }
    }
}

Example using dynamic API

open func queryWithFilterExample() throws -> Void {
    defer {
        DebugConsole.traceOut("example.NorthwindClient.queryWithFilterExample")
    }
    do {
        DebugConsole.traceIn("example.NorthwindClient.queryWithFilterExample")
        do {
            let service = self.service
            let customersEntitySet = service.entitySet(withName: "Customers")
            let customerEntityType = customersEntitySet.entityType
            let customerIDProperty = customerEntityType.property(withName: "CustomerID")
            let companyNameProperty = customerEntityType.property(withName: "CompanyName")
            let contactNameProperty = customerEntityType.property(withName: "ContactName")
            let countryProperty = customerEntityType.property(withName: "Country")
            let query = DataQuery()
                .select(customerIDProperty, companyNameProperty,
                    contactNameProperty)
                .from(customersEntitySet)
                .filter(countryProperty.equal("Germany")
                    .and(contactNameProperty.greaterEqual("N")))
            // Alternate syntax using convenience operators:
            // let query = DataQuery()
            //     .select(customerIDProperty, companyNameProperty, contactNameProperty)
            //     .from(customersEntitySet)
            //     .filter(countryProperty == "Germany" && contactNameProperty >= "N")
            let customers = try service.executeQuery(query).entityList()
            self.showCustomers(customers)
        }
    }
}
  • The wrapped value which is expected to resolve to a boolean value during query execution.

    Declaration

    Swift

    final public var value: DataValue!
  • Default initializer.

    Declaration

    Swift

    override public init()
  • Declaration

    Swift

    open func and(_ filter: DataValue) -> QueryFilter

    Parameters

    filter

    To be and'ed with self.

    Return Value

    An application of the OData ‘and’ logical operator to self and filter. This is a convenience wrapper for QueryOperator.and which allows method chaining.

  • Data type with a DataType.code of DataType.QUERY_FILTER.

    Declaration

    Swift

    override open var dataType: DataType
  • Construct a query filter by wrapping a boolean value, so it can be used by DataQuery.queryFilter or DataQuery.where.

    Declaration

    Swift

    open class func from(_ value: DataValue) -> QueryFilter

    Parameters

    value

    A boolean value.

    Return Value

    A new query filter.

  • Declaration

    Swift

    open func not() -> QueryFilter

    Return Value

    An application of the OData ‘not’ logical operator to self. This is a convenience wrapper for QueryOperator.not which allows method chaining.

  • Declaration

    Swift

    open func or(_ filter: DataValue) -> QueryFilter

    Parameters

    filter

    To be or'ed with self.

    Return Value

    An application of the OData ‘or’ logical operator to self and filter. This is a convenience wrapper for QueryOperator.or which allows method chaining.

  • Convert this data value to a string. If the dataType is defined by XML Schema Part 2: Datatypes, then the corresponding lexical format is used. JSON format is used for structured values (arrays and objects).

    Declaration

    Swift

    override open func toString() -> String

    Return Value

    Lexical representation of this data value.