DataQuery
open class DataQuery : ObjectBase, @unchecked Sendable
Encapsulates an OData query request.
A query can be defined by setting query properties, or by calling query functions which provide
a fluent interface.
Execution of a query may result in some query properties being changed (e.g. the addition of expandItems or selectItems that are required for correct execution).
Thus for thread safety, a query should be used only by a single thread at a time. Preferably a new query should be created before each query execution.
See also
DataService.executeQuery.
Example using proxy classes
open func dataQueryExample() throws -> Void {
let service = self.service
let query = DataQuery()
.select(Customer.customerID, Customer.companyName, Customer.contactName)
.filter(Customer.address.toLower().contains("king"))
.orderBy(Customer.companyName)
let customers = try service.fetchCustomers(matching: query)
self.showCustomers(customers)
}
Example using dynamic API
open func dataQueryExample() throws -> Void {
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 addressProperty = customerEntityType.property(withName: "Address")
let query = DataQuery()
.select(customerIDProperty, companyNameProperty, contactNameProperty)
.from(customersEntitySet).filter(addressProperty.toLower().contains("king"))
.orderBy(companyNameProperty)
let customers = try service.executeQuery(query).entityList()
self.showCustomers(customers)
}
-
The request path for this query. Intended for use by servers. Clients should use API calls (e.g.
from) to create request paths.Declaration
Swift
final public var requestPath: String? -
The query string for this query. Intended for use by servers. Clients should use API calls (e.g.
select,expand,filter,orderBy) to create query strings.Declaration
Swift
final public var queryString: String? -
The data format for this query’s result.
See also
DataFormat.Declaration
Swift
final public var dataFormat: Int? -
The entity type expected for the result of this query. Can be used for inference of
entitySet, if only one entity set in the data model uses this type.Declaration
Swift
final public var entityType: EntityType? -
Derived type for limiting query results.
Declaration
Swift
final public var derivedType: StructureType? -
The method call for this query. To execute a query, either this must be non-
nil, orentitySetmust be non-nil.See also
invoke.Declaration
Swift
final public var methodCall: DataMethodCall? -
Declaration
Swift
final public var resourcePath: ResourcePath? -
Property path for accessing individual properties of an entity.
See also
load.Declaration
Swift
final public var propertyPath: DataPath? -
Set to
trueif a single result is expected. This may be required ifurlhas been explicitly set.Declaration
Swift
final public var expectSingle: Bool -
The properties to select from target entities.
See also
select.Declaration
Swift
final public var selectItems: SelectItemList? -
Whether to select only distinct items.
See also
selectDistinct.Declaration
Swift
final public var distinctItems: Bool -
trueif all properties are selected (using “*”).See also
selectAll.Declaration
Swift
final public var allSelected: Bool -
trueif all key properties should be selected.See also
selectKey.Declaration
Swift
final public var keySelected: Bool -
The properties to expand from target entities.
See also
expand.Declaration
Swift
final public var expandItems: ExpandItemList? -
The filter criteria for the target entities.
See also
filter.Declaration
Swift
final public var queryFilter: QueryFilter? -
The search criteria for the target entities.
See also
search.Declaration
Swift
final public var searchExpression: SearchExpression? -
The search text to locate in target entities. Preferably, the
searchExpressionwill be used when formatting queries. UsingsearchExpressionalso ensures correct encoding of query URLs.Declaration
Swift
final public var searchText: String? -
The sort criteria for the target entities.
See also
orderBy,thenBy.Declaration
Swift
final public var sortItems: SortItemList? -
The OData transformation items as described in OData Data Aggregation.
Declaration
Swift
final public var transformValues: TransformValueList? -
A group transformation item set by
groupBy.Declaration
Swift
final public var groupTransform: GroupTransform? -
If
true, the service should return only the number of available results matching the query.See also
count.Declaration
Swift
final public var countOnly: Bool -
If
true, the service should return the total number of available results as an inline count in the result list.See also
inlineCount.Declaration
Swift
final public var countInline: Bool -
If
true, the query result entities will use sparse array storage of properties, to conserve memory. This is only applicable to queries whose result entities will not be updated.See also
sparse.Declaration
Swift
final public var sparseArray: Bool -
If
true, the client should use streamed parsing of the response.See also
stream.Declaration
Swift
final public var streamResponse: Bool -
If
true, the client should use delta parsing of the response.See also
withChangeTracking.Declaration
Swift
final public var deltaResponse: Bool -
The delta time (
deltaTokenas UTC date/time).Declaration
Swift
final public var deltaTime: GlobalDateTime? -
The delta token for use in change tracking.
Declaration
Swift
final public var deltaToken: String? -
Does the client want the server to track changes?
See also
withChangeTracking.Declaration
Swift
final public var trackChanges: Bool -
The skip token for use in server-driven paging.
Declaration
Swift
final public var skipToken: String? -
The number of initial results to skip.
See also
skip.Declaration
Swift
final public var skipCount: Int? -
The number of initial results to return.
See also
top.Declaration
Swift
final public var topCount: Int? -
Parameter alias values.
Declaration
Swift
final public var aliasValues: DataValueMap? -
Custom query options.
Declaration
Swift
final public var customOptions: StringMap? -
Elapsed time metric (unit: “MICROSECOND”) to be used for execution of this query.
Declaration
Swift
final public var timeMetric: DataMetric? -
Result count metric to be used for execution of this query.
Declaration
Swift
final public var countMetric: DataMetric? -
Default initializer.
Declaration
Swift
override public init() -
This function is an alias for
filter.Declaration
Swift
open func `where`(_ test: QueryFilter) -> DataQueryParameters
testThe query filter.
Return Value
This query.
-
Adds aggregate items (to
transformValues) for transforming the result of a query sent to an entity set. This method is only for adding aggregate transformation items (in contrast to ‘transform’ method) for readability purposes.Example for aggregations
open func aggregationExample() throws -> Void { let service = self.service let orderDetailsEntitySet = service.entitySet(withName: "Order_Detail") let orderDetailEntityType = orderDetailsEntitySet.entityType let orderDetailQuantity = orderDetailEntityType.property(withName: "Quantity") let query = DataQuery().from(orderDetailsEntitySet) let aggregateTransform = orderDetailQuantity.sum(as: "SumQuantity") _ = query.aggregate(aggregateTransform) try self.testApplyQueryResult(query: query, expectedDynamicPropertyName: "SumQuantity") let queryCount = DataQuery().from(orderDetailsEntitySet) let countAggregate = AggregateValue.count(as: "AllOrderDetails") _ = queryCount.aggregate(countAggregate) try self.testApplyQueryResult(query: queryCount, expectedDynamicPropertyName: "AllOrderDetails") }Example for aggregations
open func aggregationExample() throws -> Void { let query = DataQuery() .from(NorthwindServiceMetadata.EntitySets.orderDetails) let aggregateTransform = OrderDetail.quantity.sum(as: "SumQuantity") _ = query.aggregate(aggregateTransform) try self.testApplyQueryResult(query: query, expectedDynamicPropertyName: "SumQuantity") let queryCount = DataQuery() .from(NorthwindServiceMetadata.EntitySets.orderDetails) let countAggregate = AggregateValue.count(as: "AllOrderDetails") _ = queryCount.aggregate(countAggregate) try self.testApplyQueryResult(query: queryCount, expectedDynamicPropertyName: "AllOrderDetails") }Declaration
Swift
open func aggregate(_ items: AggregateValue...) -> DataQueryParameters
rest_itemsThe items to be added.
Return Value
This query.
-
Bind a resource as the binding parameter of a bound action/function. If
resourceis aDataPath, then setsresourcePath.ResourcePath.dataPath. Ifresourceis anEntitySet, then callsfromto setresourcePath.ResourcePath.entitySet. Ifresourceis anEntityValue, then callsloadto setresourcePath.ResourcePath.entitySetandresourcePath.ResourcePath.entityKey.Declaration
Swift
open func bind(_ resource: BindingPath) -> DataQueryParameters
resourceThe resource to be bound.
Return Value
This query.
-
Check if this query is properly configured from the client’s perspective. Note: This does not guarantee that the server will be able to execute it.
Throws
DataQueryExceptionif the query is definitely not valid.Declaration
Swift
open func check() throws -
Declaration
Swift
open func copy() -> DataQueryReturn Value
a copy of this data query which doesn’t share mutable values with this query. The resulting query will not share mutable values with this query. The resulting query might share immutable values with this query. The resulting query might share mutable metadata with this query (but metadata is expected to be finalized before query construction).
-
Set
countOnlytotrueto request only the number of matching query results.Example using proxy classes
open func navigationCountExample() throws -> Void { let service = self.service let customer = try service.fetchCustomer(matching: DataQuery() .expand(Customer.orders).top(1)) let orders = customer.orders let query = DataQuery().load(customer, Customer.orders).count() let count = try service.executeQuery(query).count() assert(count == Int64(orders.count)) }Example using proxy classes
open func collectionCountExample() throws -> Void { let service = self.service let customers = try service.fetchCustomers() let query = DataQuery().from(NorthwindServiceMetadata.EntitySets.customers) .count() let count = try service.executeQuery(query).count() assert(count == Int64(customers.count)) }Example using dynamic API
open func collectionCountExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customers = try service.executeQuery(DataQuery().from(customersEntitySet)) .entityList() let query = DataQuery().from(customersEntitySet).count() let count = try service.executeQuery(query).count() assert(count == Int64(customers.length)) }Example using dynamic API
open func navigationCountExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customerEntityType = customersEntitySet.entityType let ordersProperty = customerEntityType.property(withName: "Orders") let customer = try service.executeQuery(DataQuery().from(customersEntitySet) .expand(ordersProperty).top(1)) .entityList().first() let orders = ordersProperty.entityList(from: customer) let query = DataQuery().load(customer, ordersProperty).count() let count = try service.executeQuery(query).count() assert(count == Int64(orders.length)) }Declaration
Swift
open func count() -> DataQueryReturn Value
This query.
-
Alter this query to include all current entities (non-pending, or with pending create/update requests) as well as deleted entities (pending deletion). This is relevant in offline scenarios.
Declaration
Swift
open func currentOrDeleted() -> DataQueryReturn Value
This query.
-
Add a custom option to
customOptions.Declaration
Swift
open func custom(_ name: String, _ value: String) -> DataQueryParameters
nameOption name.
valueOption value.
Return Value
This query.
-
Alter this query to defer its execution. This is particular useful when using actions/functions with proxy classes. It allows the use of deferred proxy method calls together with request batches.
Example using proxy classes
open func invokeActionsInBatch() throws -> Void { let service = self.service let batch = RequestBatch() let action1 = DataQuery() let action2 = DataQuery() try service.deleteVideosInCategory("Romance", query: action1.deferExecution()) try service.deleteVideosInCategory("Suspense", query: action2.deferExecution()) batch.addAction(call: action1) batch.addAction(call: action2) try service.processBatch(batch) batch.checkActionResult(for: action1) batch.checkActionResult(for: action2) }Example using proxy classes
open func invokeFunctionsInBatch() throws -> Void { let service = self.service let batch = RequestBatch() let query1 = DataQuery() let query2 = DataQuery() _ = try service.videosInCategory("Romance", query: query1.deferExecution()) _ = try service.videosInCategory("Suspense", query: query2.deferExecution()) batch.addFunction(call: query1) batch.addFunction(call: query2) try service.processBatch(batch) let videos1 = try Video.array(from: batch.functionResult(for: query1) .entityList()) let videos2 = try Video.array(from: batch.functionResult(for: query2) .entityList()) self.showVideos(videos1) self.showVideos(videos2) }Declaration
Swift
open func deferExecution() -> DataQueryReturn Value
This query.
-
Deprecated. Use search(SearchExpression) or set the
searchTextproperty.Declaration
Swift
@available(*, deprecated) open func search(_ text: String) -> DataQueryParameters
textThe search expression in text form.
Return Value
This query.
-
The entity set expected for the result of this query. To execute a query, either this must be non-
nil, ormethodCallmust be non-nil.Declaration
Swift
open var entitySet: EntitySet? { get set } -
Add properties (to
expandItems) for expanding from the target entity.Example using proxy classes
open func expandExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .filter(Customer.customerID.equal("ALFKI").or(Customer.customerID.equal("ANATR"))) .expand(Customer.orders).orderBy(Customer.companyName) let customers = try service.fetchCustomers(matching: query) var countOrders = 0 for customer in customers { self.showCustomer(customer) let orders = customer.orders for order in orders { let orderID = order.orderID try Example.show(" Order ", Example.formatInt(orderID)) countOrders = countOrders + 1 } } assert(countOrders > 0) }Example using dynamic API
open func expandExample() throws -> Void { 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 ordersProperty = customerEntityType.property(withName: "Orders") let orderIDProperty = ordersProperty.itemEntityType.property(withName: "OrderID") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).expand(ordersProperty) .filter(customerIDProperty.equal("ALFKI").or(customerIDProperty.equal("ANATR"))) .orderBy(companyNameProperty) let customers = try service.executeQuery(query).entityList() var countOrders = 0 for customer in customers { self.showCustomer(customer) let orders = ordersProperty.entityList(from: customer) for order in orders { let orderID = orderIDProperty.intValue(from: order) try Example.show(" Order ", Example.formatInt(orderID)) countOrders = countOrders + 1 } } assert(countOrders > 0) }Declaration
Swift
open func expand(_ items: PropertyPath...) -> DataQueryParameters
rest_itemsThe items to be expanded.
Return Value
This query.
-
Add a property with a nested query to
expandItems. See theexpandWithQueryExample2below for an abbreviated syntax that implicitly creates the nested query.Example using proxy classes
open func expandWithQueryExample1() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .filter(Customer.customerID.equal("ALFKI").or(Customer.customerID.equal("ANATR"))) .expand(Customer.orders, withQuery: DataQuery().select(Order.orderID) .expand(Order.orderDetails, withQuery: DataQuery().select(OrderDetail.quantity, OrderDetail.unitPrice))) .orderBy(Customer.companyName) let customers = try service.fetchCustomers(matching: query) var countDetails = 0 for customer in customers { self.showCustomer(customer) let orders = customer.orders for order in orders { let orderID = order.orderID var totalPrice = BigDecimal(0) for orderDetail in order.orderDetails { totalPrice = totalPrice.add(DecimalFunction.fromShort(orderDetail.quantity) .multiply(orderDetail.unitPrice)) countDetails = countDetails + 1 } try Example.show("Order ", Example.formatInt(orderID), ": total price ", Example.formatDecimal(totalPrice)) } } assert(countDetails > 0) }Example using proxy classes
open func expandWithQueryExample2() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .filter(Customer.customerID.equal("ALFKI").or(Customer.customerID.equal("ANATR"))) .expand(Customer.orders.select(Order.orderID) .expand(Order.orderDetails.select(OrderDetail.quantity, OrderDetail.unitPrice))) .orderBy(Customer.companyName) let customers = try service.fetchCustomers(matching: query) var countDetails = 0 for customer in customers { self.showCustomer(customer) let orders = customer.orders for order in orders { let orderID = order.orderID var totalPrice = BigDecimal(0) for orderDetail in order.orderDetails { totalPrice = totalPrice.add(DecimalFunction.fromShort(orderDetail.quantity) .multiply(orderDetail.unitPrice)) countDetails = countDetails + 1 } try Example.show("Order ", Example.formatInt(orderID), ": total price ", Example.formatDecimal(totalPrice)) } } assert(countDetails > 0) }Example using dynamic API
open func expandWithQueryExample() throws -> Void { 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 ordersProperty = customerEntityType.property(withName: "Orders") let orderIDProperty = ordersProperty.itemEntityType.property(withName: "OrderID") let orderDetailsProperty = ordersProperty.itemEntityType.property(withName: "Order_Details") let quantityProperty = orderDetailsProperty.itemEntityType.property(withName: "Quantity") let unitPriceProperty = orderDetailsProperty.itemEntityType.property(withName: "UnitPrice") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet) .filter(customerIDProperty.equal("ALFKI").or(customerIDProperty.equal("ANATR"))) .expand(ordersProperty, withQuery: DataQuery().select(orderIDProperty) .expand(orderDetailsProperty, withQuery: DataQuery().select(quantityProperty, unitPriceProperty))) .orderBy(companyNameProperty) let customers = try service.executeQuery(query).entityList() for customer in customers { self.showCustomer(customer) let orders = ordersProperty.entityList(from: customer) for order in orders { let orderID = orderIDProperty.intValue(from: order) var totalPrice = BigDecimal(0) for orderDetail in orderDetailsProperty.entityList(from: order) { let quantity = quantityProperty.shortValue(from: orderDetail) let unitPrice = unitPriceProperty.decimalValue(from: orderDetail) totalPrice = totalPrice.add(DecimalFunction.fromShort(quantity) .multiply(unitPrice)) } try Example.show("Order ", Example.formatInt(orderID), ": total price ", Example.formatDecimal(totalPrice)) } } }Declaration
Swift
open func expand(_ item: PropertyPath, withQuery query: DataQuery) -> DataQueryParameters
itemItem to be expanded.
queryQuery to control expansion.
Return Value
This query.
-
Declaration
Swift
open func expandedProperties() -> StringSetReturn Value
The names of all properties expanded by this query.
-
Declaration
Swift
open func expandsProperty(_ property: Property) -> BoolParameters
propertyProperty to check for.
Return Value
trueif this query expandspropertyfrom the target entity. -
Set
expectedTypeandexpectSingle, depending on thetypeparameter.Declaration
Swift
open func expect(_ type: DataType) -> DataQueryParameters
typeExpected type.
Return Value
This query.
-
Modify
queryFilterto be and'ed withtest(or set totestifqueryFilterwasnil).Example using proxy classes
open func queryWithFilterExample() throws -> Void { 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 proxy classes
open func filterByDateExample() throws -> Void { let service = self.service let oneWeekAgo = GlobalDateTime.now().plusDays(-7) let query = DataQuery().filter(Order.orderDate.greaterThan(oneWeekAgo)) // Alternate syntax using convenience operators: // let query = DataQuery().filter(Order.orderDate >= oneWeekAgo) let orders = try service.fetchOrders(matching: query) self.showOrders(orders) }Example using proxy classes
open func filterByEnumExample() throws -> Void { let service = self.service let query = DataQuery() .filter(TrippinPerson.gender.equal(TrippinServiceMetadata.EnumValues.TrippinPersonGender.female)) // Alternate syntax using convenience operators: // let query = DataQuery().filter(TrippinPerson.gender == TrippinPersonGender.female.enumValue) let people = try service.fetchPeople(matching: query) try self.showPeople(people) }Example using dynamic API
open func queryWithFilterExample() throws -> Void { 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) }Example using dynamic API
open func filterByDateExample() throws -> Void { let service = self.service let ordersEntitySet = service.entitySet(withName: "Orders") let orderEntityType = ordersEntitySet.entityType let orderDateProperty = orderEntityType.property(withName: "OrderDate") let oneWeekAgo = GlobalDateTime.now().plusDays(-7) let query = DataQuery().from(ordersEntitySet) .filter(orderDateProperty.greaterThan(oneWeekAgo)) // Alternate syntax using convenience operators: // let query = DataQuery().filter(orderDateProperty >= oneWeekAgo) let orders = try service.executeQuery(query).entityList() self.showOrders(orders) }Example using dynamic API
open func filterByEnumExample() throws -> Void { let service = self.service let peopleEntitySet = service.entitySet(withName: "People") let personEntityType = peopleEntitySet.entityType let genderProperty = personEntityType.property(withName: "Gender") let genderEnumType = service.metadata.enumType(withName: "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender") let female = genderEnumType.member(name: "Female") let query = DataQuery().from(peopleEntitySet) .filter(genderProperty.equal(female)) // Alternate syntax using convenience operators: // let query = DataQuery().filter(genderProperty == genderFemale) let people = try service.executeQuery(query).entityList() try self.showPeople(people) }Declaration
Swift
open func filter(_ test: QueryFilter) -> DataQueryParameters
testThe query filter.
Return Value
This query.
-
Declaration
Swift
open func filteredProperties() -> StringSetReturn Value
The names of all properties filtered by this query.
-
Declaration
Swift
open func filtersProperty(_ property: Property) -> BoolParameters
propertyProperty to check for.
Return Value
trueif this query filterspropertyfrom the target entity. -
Set the
entitySetproperty to identify this query’s target entity set.Example using proxy classes
open func fromExample() throws -> Void { let service = self.service let customers = try service.fetchCustomers() for customer in customers { self.showCustomer(customer) } }Example using dynamic API
open func fromExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let query = DataQuery().from(customersEntitySet) let customers = try service.executeQuery(query).entityList() for customer in customers { self.showCustomer(customer) } }Declaration
Swift
open func from(_ entitySet: EntitySet) -> DataQueryParameters
entitySetThe target entity set.
Return Value
This query.
-
Set the
entitySetproperty to identify this query’s target entity set, but only if theentitySetproperty wasn’t previously set. This function is intended for use by generated proxy classes.Declaration
Swift
open func fromDefault(_ entitySet: EntitySet) -> DataQueryParameters
entitySetThe target entity set.
Return Value
This query.
-
Adds a group transformation item to the DataQuery with the property paths given in the parameter list. Note: If this method is called then all the transformation and aggregation items added to the query will be applied to the group transformation in the query.
Example for transformations
open func transformationExample() throws -> Void { let service = self.service let employeeEntitySet = service.entitySet(withName: "Employees") let employeeEntityType = employeeEntitySet.entityType let employeeReportsToProperty = employeeEntityType.property(withName: "ReportsTo") let ordersProperty = employeeEntityType.property(withName: "Orders") let orderID = ordersProperty.itemEntityType.property(withName: "OrderID") let countryProperty = employeeEntityType.property(withName: "Country") let queryGroup = DataQuery().from(employeeEntitySet) let filterGroupTransform = FilterTransform.of(QueryOperator.equal(countryProperty, StringValue.of("Budapest"))) let groupTransform = GroupTransform.groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(orderID).countDistinct(as: "TotalOrders")) _ = queryGroup.transform(groupTransform) try self.testApplyQueryResult(query: queryGroup, expectedDynamicPropertyName: "TotalOrders") let groupTransformForQuery = DataQuery().from(employeeEntitySet) .groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(orderID).countDistinct(as: "TotalOrders")) .transform(filterGroupTransform) try self.testApplyQueryResult(query: groupTransformForQuery, expectedDynamicPropertyName: "TotalOrders") let queryTopPercent = DataQuery().from(employeeEntitySet) let topPercentTransform = TopTransform.percent(amount: Double(50), value: employeeReportsToProperty) _ = queryTopPercent.transform(topPercentTransform) try self.testApplyQueryResult(query: queryTopPercent, expectedDynamicPropertyName: nil) let queryExpand = DataQuery().from(employeeEntitySet) let expandTransform = ExpandTransform.withFilter(ordersProperty, filter: FilterTransform.of(QueryOperator.equal(employeeReportsToProperty, IntValue.of(1000)))) _ = queryExpand.transform(expandTransform) try self.testApplyQueryResult(query: queryExpand, expectedDynamicPropertyName: nil) let employee1Property = employeeEntityType.property(withName: "Employee1") let expandWithExpandTransform = ExpandTransform.withExpand(employee1Property, expand: expandTransform) let queryExpand1 = DataQuery().from(employeeEntitySet) _ = queryExpand1.transform(expandWithExpandTransform) try self.testApplyQueryResult(query: queryExpand1, expectedDynamicPropertyName: nil) let queryOrderBy = DataQuery().from(employeeEntitySet) let orderTransform = OrderTransform.orderBy(SortItem.of(countryProperty, SortOrder.descending)) let skipTransform = SkipTransform.skip(5) let topTransform = TopTransform.top(10) _ = queryOrderBy.transform(orderTransform.chain(skipTransform) .chain(topTransform)) try self.testApplyQueryResult(query: queryOrderBy, expectedDynamicPropertyName: nil) let orderDetailsEntitySet = service.entitySet(withName: "Order_Details") let ordersQuantityProperty = orderDetailsEntitySet.entityType.property(withName: "Quantity") let queryConcat = DataQuery().from(orderDetailsEntitySet) let concatTransform = ConcatTransform.create(IdentityTransform.create(), ordersQuantityProperty.sum(as: "SumQuantity")) _ = queryConcat.transform(concatTransform) try self.testApplyQueryResult(query: queryConcat, expectedDynamicPropertyName: "SumQuantity") let var_employeeEntitySet = service.entitySet(withName: "Employees") let var_employeeEntityType = var_employeeEntitySet.entityType let employeeIDProperty = var_employeeEntityType.property(withName: "EmployeeID") let firstNameProperty = var_employeeEntityType.property(withName: "FirstName") let lastNameProperty = var_employeeEntityType.property(withName: "LastName") let var_ordersProperty = var_employeeEntityType.property(withName: "Orders") let ordersEntitySet = service.entitySet(withName: "Orders") let orderEntityType = ordersEntitySet.entityType let orderIDProperty = orderEntityType.property(withName: "OrderID") let queryJoin = DataQuery().from(var_employeeEntitySet) let joinTransform = JoinTransform.join(var_ordersProperty, alias: "Order") _ = joinTransform.transform(GroupTransform.groupBy(employeeIDProperty, firstNameProperty, lastNameProperty) .aggregate(DataPath.ofDynamic("Order").path(orderIDProperty).countDistinct(as: "TotalOrders"))) _ = queryJoin.transform(joinTransform) try self.testApplyQueryResult(query: queryJoin, expectedDynamicPropertyName: "Order") }Example for transformations
open func transformationExample() throws -> Void { let queryGroup = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let groupTransform = GroupTransform.groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderID).countDistinct(as: "TotalOrders")) _ = queryGroup.transform(groupTransform) try self.testApplyQueryResult(query: queryGroup, expectedDynamicPropertyName: "TotalOrders") let filterGroupTransform = FilterTransform.of(QueryOperator.equal(Employee.country, StringValue.of("Budapest"))) let groupTransformForQuery = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) .groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderID).countDistinct(as: "TotalOrders")) .transform(filterGroupTransform) try self.testApplyQueryResult(query: groupTransformForQuery, expectedDynamicPropertyName: "TotalOrders") let queryTopPercent = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let topPercentTransform = TopTransform.percent(amount: Double(50), value: Employee.reportsTo) _ = queryTopPercent.transform(topPercentTransform) try self.testApplyQueryResult(query: queryTopPercent, expectedDynamicPropertyName: nil) let queryExpand = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let expandTransform = ExpandTransform.withFilter(Employee.orders, filter: FilterTransform.of(QueryOperator.equal(Employee.reportsTo, IntValue.of(1000)))) _ = queryExpand.transform(expandTransform) try self.testApplyQueryResult(query: queryExpand, expectedDynamicPropertyName: nil) let expandWithExpandTransform = ExpandTransform.withExpand(Employee.employee1, expand: expandTransform) let queryExpand1 = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) _ = queryExpand1.transform(expandWithExpandTransform) try self.testApplyQueryResult(query: queryExpand1, expectedDynamicPropertyName: nil) let queryOrderBy = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let orderTransform = OrderTransform.orderBy(SortItem.of(Customer.country, SortOrder.descending)) let skipTransform = SkipTransform.skip(5) let topTransform = TopTransform.top(10) _ = queryOrderBy.transform(orderTransform.chain(skipTransform) .chain(topTransform)) try self.testApplyQueryResult(query: queryOrderBy, expectedDynamicPropertyName: nil) let queryConcat = DataQuery() .from(NorthwindServiceMetadata.EntitySets.orderDetails) let concatTransform = ConcatTransform.create(IdentityTransform.create(), OrderDetail.quantity.sum(as: "SumQuantity")) _ = queryConcat.transform(concatTransform) try self.testApplyQueryResult(query: queryConcat, expectedDynamicPropertyName: "SumQuantity") let queryJoin = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let joinTransform = JoinTransform.join(Employee.orders, alias: "Order") _ = joinTransform.transform(GroupTransform.groupBy(Employee.employeeID, Employee.firstName, Employee.lastName) .aggregate(DataPath.ofDynamic("Order").path(Order.orderID).countDistinct(as: "TotalOrders"))) _ = queryJoin.transform(joinTransform) try self.testApplyQueryResult(query: queryJoin, expectedDynamicPropertyName: "Order") }Declaration
Swift
open func groupBy(_ items: PropertyPath...) -> DataQueryParameters
rest_itemsThe property paths to be added to the group transformation.
Return Value
This query.
-
Alter this query to apply to all entities with pending changes.
Declaration
Swift
open func hasPendingChanges() -> DataQueryReturn Value
This query.
-
Alter this query to apply to all entities with original state.
Declaration
Swift
open func ifOriginalEntity() -> DataQueryReturn Value
This query.
-
Set
countInlinetotrueto request an inline count in the server’s response.Example using proxy classes
open func inlineCountExample() throws -> Void { let service = self.service let query = DataQuery().from(NorthwindServiceMetadata.EntitySets.customers) .skip(20).top(10).inlineCount() let result = try service.executeQuery(query) let customers = try Customer.array(from: result.entityList()) let count = try result.inlineCount() assert(customers.count == 10) assert(count > Int64(10)) }Example using dynamic API
open func inlineCountExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let query = DataQuery().from(customersEntitySet).skip(20).top(10) .inlineCount() let result = try service.executeQuery(query) let customers = try result.entityList() let count = try result.inlineCount() assert(customers.length == 10) assert(count > Int64(10)) }Declaration
Swift
open func inlineCount() -> DataQueryReturn Value
This query.
-
Set
methodCallto associate this query with an action/function invocation.See also
bind, for setting the binding parameter for a bound action/function.Example using proxy classes
open func invokeExample() throws -> Void { let service = self.service let person = try service.personWithMostFriends() try self.showPerson(person) }Example using dynamic API
open func invokeExample() throws -> Void { let service = self.service let functionImport = service.dataMethod(withName: "GetPersonWithMostFriends") let query = DataQuery().invoke(functionImport) let person = try service.executeQuery(query).requiredEntity() try self.showPerson(person) }Declaration
Swift
open func invoke(_ method: DataMethod, _ parameters: ParameterList = ParameterList.empty) -> DataQueryParameters
methodData method to be called (action or function).
parametersMethod parameters.
Return Value
This query.
-
Set the
resourcePathproperty to identify this query’s entity sets for a cross join.Example using proxy classes
open func joinExample() throws -> Void { let service = self.service let c = NorthwindService.customers let o = NorthwindService.orders let query = DataQuery().join(c, o).expand(c.select(Customer.companyName)) .expand(o.select(Order.orderDate)) .filter(c.path(Customer.customerID).equal(o.path(Order.customerID))) let resultList = try service.executeQuery(query).complexList() for resultItem in resultList { let customer = (resultItem.dynamicValue(name: c.localName) as! Customer) let order = (resultItem.dynamicValue(name: o.localName) as! Order) self.showCustomer(customer) self.showOrder(order) } }Example using dynamic API
open func joinExample() throws -> Void { 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 ordersEntitySet = service.entitySet(withName: "Orders") let orderEntityType = ordersEntitySet.entityType let orderCustomerID = orderEntityType.property(withName: "CustomerID") let orderDateProperty = customerEntityType.property(withName: "OrderDate") let query = DataQuery().join(customersEntitySet, ordersEntitySet) .expand(customersEntitySet.select(companyNameProperty)) .expand(ordersEntitySet.select(orderDateProperty)) .filter(customersEntitySet.path(customerIDProperty) .equal(ordersEntitySet.path(orderCustomerID))) let resultList = try service.executeQuery(query).complexList() for resultItem in resultList { let customer = (resultItem.dynamicValue(name: customersEntitySet.localName) as! EntityValue) let order = (resultItem.dynamicValue(name: ordersEntitySet.localName) as! EntityValue) self.showCustomer(customer) self.showOrder(order) } }Declaration
Swift
open func join(_ entitySets: EntitySet...) -> DataQueryParameters
rest_entitySetsThe entity sets to be joined.
Return Value
This query.
-
Set
entitySetandentityKeyto configure this query to load an existing entity. Equivalent to callingfrom(entity.entitySet).withKey(entity.entityKey).Declaration
Swift
open func load(_ entity: EntityValue, _ path: PropertyPath? = nil) -> DataQueryParameters
entityThe entity to be loaded.
pathOptionally specify
propertyPath.Return Value
This query.
-
Construct a new DataQuery if the
queryparameter isnil.Declaration
Swift
open class func newIfNull(query: DataQuery?) -> DataQueryParameters
queryQuery to be checked.
Return Value
The
queryparameter, if non-nil. Otherwise a new DataQuery. -
Add to
sortItemsa value for result ordering.Example using proxy classes
open func orderByExample() throws -> Void { // Find the 3 artists born nearest to Avila, Spain. let service = self.service let avila = GeographyPoint.with(latitude: 40.6567, longitude: -4.6812) let query = DataQuery().top(3).orderBy(Artist.placeOfBirth.geoDistance(avila)) let artists = try service.fetchArtists(matching: query) self.showArtists(artists) }Example using dynamic API
open func orderByExample() throws -> Void { // Find the 3 artists born nearest to Avila, Spain. let service = self.service let artistsEntitySet = service.entitySet(withName: "Artists") let artistEntityType = artistsEntitySet.entityType let placeOfBirthProperty = artistEntityType.property(withName: "placeOfBirth") let avila = GeographyPoint.with(latitude: 40.6567, longitude: -4.6812) let query = DataQuery().top(3).from(artistsEntitySet) .orderBy(placeOfBirthProperty.geoDistance(avila)) let artists = try service.executeQuery(query).entityList() self.showArtists(artists) }Declaration
Swift
open func orderBy(_ value: QueryValue, _ order: SortOrder = SortOrder.ascending) -> DataQueryParameters
valueValue for ordering.
orderThe sort order (defaults to ascending).
Return Value
This query.
-
Set
pageSizeto specify the page-size for server-driven paging of results. Note: the server is not required to respect this setting. But if this setting is used, the client should expect to have to follow next-links.Example using proxy classes
open func queryWithPageExample() throws -> Void { let service = self.service let expected = try service.executeQuery(DataQuery() .from(NorthwindServiceMetadata.EntitySets.customers).count()) .count() var found = 0 var query = DataQuery().from(NorthwindServiceMetadata.EntitySets.customers) .page(5) repeat { let result = try service.executeQuery(query) let customers = try Customer.array(from: result.entityList()) self.showCustomers(customers) found = found &+ customers.count query = try result.nextQuery() } while query.url != nil assert(Int64(found) == expected) }Example using dynamic API
open func queryWithPageExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") var query = DataQuery().from(customersEntitySet).page(5) repeat { let result = try service.executeQuery(query) let customers = try result.entityList() self.showCustomers(customers) query = try result.nextQuery() } while query.url != nil }Declaration
Swift
open func page(_ size: Int) -> DataQueryParameters
sizeClient-requested page size for use by server-driven paging.
Return Value
This query.
-
Set
propertyPathto identify this query’s target path.Declaration
Swift
open func path(_ target: DataPath) -> DataQueryParameters
targetThe target path.
Return Value
This query.
-
Set
propertyPathto identify this query’s target property.Declaration
Swift
open func property(_ target: Property) -> DataQueryParameters
targetThe target property.
Return Value
This query.
-
Set
resourcePathto identify this query’s target resource.Declaration
Swift
open func resource(_ target: ResourcePath) -> DataQueryParameters
targetThe target resource.
Return Value
This query.
-
Set
searchExpressionfor free-text searching.Example using proxy classes
open func searchExample() throws -> Void { let service = self.service let query = DataQuery().search(SearchTerm.word("Juice")) let products = try service.fetchProducts(matching: query) self.showProducts(products) }Example using dynamic API
open func searchExample() throws -> Void { let service = self.service let productsEntitySet = service.entitySet(withName: "Products") let query = DataQuery().from(productsEntitySet).search(SearchTerm.word("Juice")) let products = try service.executeQuery(query).entityList() self.showProducts(products) }Declaration
Swift
open func search(_ expression: SearchExpression) -> DataQueryParameters
expressionThe search expression.
Return Value
This query.
-
Add properties (to
selectItems) for selecting from the target entity.Example using proxy classes
open func selectExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) let customers = try service.fetchCustomers(matching: query) for customer in customers { self.showCustomer(customer) } }Example using dynamic API
open func selectExample() throws -> Void { 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 query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet) let customers = try service.executeQuery(query).entityList() for customer in customers { self.showCustomer(customer) } }Declaration
Swift
open func select(_ items: PropertyPath...) -> DataQueryParameters
rest_itemsThe items to be selected.
Return Value
This query.
-
Set
allSelectedtotrue.Declaration
Swift
open func selectAll() -> DataQueryReturn Value
This query.
-
Add properties (to
selectItems) for selecting from the target entity and setdistinctItemstotrue. Note that this isn’t a standard OData query option, so servers might ignore it.Declaration
Swift
open func selectDistinct(_ items: PropertyPath...) -> DataQueryParameters
rest_itemsThe items to be selected.
Return Value
This query.
-
Set
keySelectedtotrue.Declaration
Swift
open func selectKey() -> DataQueryReturn Value
This query.
-
Declaration
Swift
open func selectedProperties() -> StringSetReturn Value
The names of all properties selected by this query. If
allSelectedorkeySelectedis set, then calling this function might result in additional items being added toselectItemsso that the resulting set of properties is consistent with the other configured query options. -
Declaration
Swift
open func selectsProperty(_ property: Property) -> BoolParameters
propertyProperty to check for.
Return Value
trueif this query selectspropertyfrom the target entity. -
Set
skipCountto specify the number of initial results to return.Example using proxy classes
open func queryWithSkipExample() throws -> Void { let service = self.service let query = DataQuery().skip(20).top(10) let customers = try service.fetchCustomers(matching: query) self.showCustomers(customers) assert(customers.count == 10) }Example using dynamic API
open func queryWithSkipExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let query = DataQuery().from(customersEntitySet).skip(20).top(10) let customers = try service.executeQuery(query).entityList() self.showCustomers(customers) assert(customers.length == 10) }Declaration
Swift
open func skip(_ count: Int) -> DataQueryParameters
countNumber of initial results for query execution to skip.
Return Value
This query.
-
See also
orderBy,thenBy.Declaration
Swift
open func sortedByProperties() -> StringSetReturn Value
The names of all properties used for sorting by this query.
-
Set
sparseArraytotrue, so that query result entities will use sparse array storage of properties, to conserve memory. This is only applicable to queries whose result entities will not be updated.Declaration
Swift
open func sparse() -> DataQueryReturn Value
This query.
-
Set
streamResponsetotrueto request streamed response processing.Declaration
Swift
open func stream() -> DataQueryReturn Value
This query.
-
Add to
sortItemsa value for result ordering. This function is an alias fororderBy. By convention to improve readability when multiple ordering values are required, the first ordering value is added usingorderBy, and subsequent ordering values are added usingthenBy.Example using proxy classes
open func thenByExample() throws -> Void { let service = self.service let query = DataQuery().orderBy(Artist.lastName).thenBy(Artist.firstName) let artists = try service.fetchArtists(matching: query) self.showArtists(artists) }Example using dynamic API
open func thenByExample() throws -> Void { let service = self.service let artistsEntitySet = service.entitySet(withName: "Artists") let artistEntityType = artistsEntitySet.entityType let lastNameProperty = artistEntityType.property(withName: "lastName") let firstNameProperty = artistEntityType.property(withName: "firstName") let query = DataQuery().from(artistsEntitySet).orderBy(lastNameProperty) .thenBy(firstNameProperty) let artists = try service.executeQuery(query).entityList() self.showArtists(artists) }Declaration
Swift
open func thenBy(_ value: QueryValue, _ order: SortOrder = SortOrder.ascending) -> DataQueryParameters
valueValue for ordering.
orderThe sort order (defaults to ascending).
Return Value
This query.
-
Declaration
Swift
override open func toString() -> StringReturn Value
A string representation of this object.
-
Set
topCountto specify the maximum number of results to return.Example using proxy classes
open func queryWithTopExample() throws -> Void { let service = self.service let query = DataQuery().top(10) let customers = try service.fetchCustomers(matching: query) self.showCustomers(customers) assert(customers.count == 10) }Example using dynamic API
open func queryWithTopExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let query = DataQuery().from(customersEntitySet).top(10) let customers = try service.executeQuery(query).entityList() self.showCustomers(customers) assert(customers.length == 10) }Declaration
Swift
open func top(_ count: Int) -> DataQueryParameters
countMaximum number of results for query execution to return.
Return Value
This query.
-
Adds transform items (to
transformValues) for transforming the result of a query sent to an entity set.Example for transformations
open func transformationExample() throws -> Void { let service = self.service let employeeEntitySet = service.entitySet(withName: "Employees") let employeeEntityType = employeeEntitySet.entityType let employeeReportsToProperty = employeeEntityType.property(withName: "ReportsTo") let ordersProperty = employeeEntityType.property(withName: "Orders") let orderID = ordersProperty.itemEntityType.property(withName: "OrderID") let countryProperty = employeeEntityType.property(withName: "Country") let queryGroup = DataQuery().from(employeeEntitySet) let filterGroupTransform = FilterTransform.of(QueryOperator.equal(countryProperty, StringValue.of("Budapest"))) let groupTransform = GroupTransform.groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(orderID).countDistinct(as: "TotalOrders")) _ = queryGroup.transform(groupTransform) try self.testApplyQueryResult(query: queryGroup, expectedDynamicPropertyName: "TotalOrders") let groupTransformForQuery = DataQuery().from(employeeEntitySet) .groupBy(employeeReportsToProperty) .aggregate(ordersProperty.path(orderID).countDistinct(as: "TotalOrders")) .transform(filterGroupTransform) try self.testApplyQueryResult(query: groupTransformForQuery, expectedDynamicPropertyName: "TotalOrders") let queryTopPercent = DataQuery().from(employeeEntitySet) let topPercentTransform = TopTransform.percent(amount: Double(50), value: employeeReportsToProperty) _ = queryTopPercent.transform(topPercentTransform) try self.testApplyQueryResult(query: queryTopPercent, expectedDynamicPropertyName: nil) let queryExpand = DataQuery().from(employeeEntitySet) let expandTransform = ExpandTransform.withFilter(ordersProperty, filter: FilterTransform.of(QueryOperator.equal(employeeReportsToProperty, IntValue.of(1000)))) _ = queryExpand.transform(expandTransform) try self.testApplyQueryResult(query: queryExpand, expectedDynamicPropertyName: nil) let employee1Property = employeeEntityType.property(withName: "Employee1") let expandWithExpandTransform = ExpandTransform.withExpand(employee1Property, expand: expandTransform) let queryExpand1 = DataQuery().from(employeeEntitySet) _ = queryExpand1.transform(expandWithExpandTransform) try self.testApplyQueryResult(query: queryExpand1, expectedDynamicPropertyName: nil) let queryOrderBy = DataQuery().from(employeeEntitySet) let orderTransform = OrderTransform.orderBy(SortItem.of(countryProperty, SortOrder.descending)) let skipTransform = SkipTransform.skip(5) let topTransform = TopTransform.top(10) _ = queryOrderBy.transform(orderTransform.chain(skipTransform) .chain(topTransform)) try self.testApplyQueryResult(query: queryOrderBy, expectedDynamicPropertyName: nil) let orderDetailsEntitySet = service.entitySet(withName: "Order_Details") let ordersQuantityProperty = orderDetailsEntitySet.entityType.property(withName: "Quantity") let queryConcat = DataQuery().from(orderDetailsEntitySet) let concatTransform = ConcatTransform.create(IdentityTransform.create(), ordersQuantityProperty.sum(as: "SumQuantity")) _ = queryConcat.transform(concatTransform) try self.testApplyQueryResult(query: queryConcat, expectedDynamicPropertyName: "SumQuantity") let var_employeeEntitySet = service.entitySet(withName: "Employees") let var_employeeEntityType = var_employeeEntitySet.entityType let employeeIDProperty = var_employeeEntityType.property(withName: "EmployeeID") let firstNameProperty = var_employeeEntityType.property(withName: "FirstName") let lastNameProperty = var_employeeEntityType.property(withName: "LastName") let var_ordersProperty = var_employeeEntityType.property(withName: "Orders") let ordersEntitySet = service.entitySet(withName: "Orders") let orderEntityType = ordersEntitySet.entityType let orderIDProperty = orderEntityType.property(withName: "OrderID") let queryJoin = DataQuery().from(var_employeeEntitySet) let joinTransform = JoinTransform.join(var_ordersProperty, alias: "Order") _ = joinTransform.transform(GroupTransform.groupBy(employeeIDProperty, firstNameProperty, lastNameProperty) .aggregate(DataPath.ofDynamic("Order").path(orderIDProperty).countDistinct(as: "TotalOrders"))) _ = queryJoin.transform(joinTransform) try self.testApplyQueryResult(query: queryJoin, expectedDynamicPropertyName: "Order") }Example for transformations
open func transformationExample() throws -> Void { let queryGroup = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let groupTransform = GroupTransform.groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderID).countDistinct(as: "TotalOrders")) _ = queryGroup.transform(groupTransform) try self.testApplyQueryResult(query: queryGroup, expectedDynamicPropertyName: "TotalOrders") let filterGroupTransform = FilterTransform.of(QueryOperator.equal(Employee.country, StringValue.of("Budapest"))) let groupTransformForQuery = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) .groupBy(Employee.reportsTo) .aggregate(Employee.orders.path(Order.orderID).countDistinct(as: "TotalOrders")) .transform(filterGroupTransform) try self.testApplyQueryResult(query: groupTransformForQuery, expectedDynamicPropertyName: "TotalOrders") let queryTopPercent = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let topPercentTransform = TopTransform.percent(amount: Double(50), value: Employee.reportsTo) _ = queryTopPercent.transform(topPercentTransform) try self.testApplyQueryResult(query: queryTopPercent, expectedDynamicPropertyName: nil) let queryExpand = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let expandTransform = ExpandTransform.withFilter(Employee.orders, filter: FilterTransform.of(QueryOperator.equal(Employee.reportsTo, IntValue.of(1000)))) _ = queryExpand.transform(expandTransform) try self.testApplyQueryResult(query: queryExpand, expectedDynamicPropertyName: nil) let expandWithExpandTransform = ExpandTransform.withExpand(Employee.employee1, expand: expandTransform) let queryExpand1 = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) _ = queryExpand1.transform(expandWithExpandTransform) try self.testApplyQueryResult(query: queryExpand1, expectedDynamicPropertyName: nil) let queryOrderBy = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let orderTransform = OrderTransform.orderBy(SortItem.of(Customer.country, SortOrder.descending)) let skipTransform = SkipTransform.skip(5) let topTransform = TopTransform.top(10) _ = queryOrderBy.transform(orderTransform.chain(skipTransform) .chain(topTransform)) try self.testApplyQueryResult(query: queryOrderBy, expectedDynamicPropertyName: nil) let queryConcat = DataQuery() .from(NorthwindServiceMetadata.EntitySets.orderDetails) let concatTransform = ConcatTransform.create(IdentityTransform.create(), OrderDetail.quantity.sum(as: "SumQuantity")) _ = queryConcat.transform(concatTransform) try self.testApplyQueryResult(query: queryConcat, expectedDynamicPropertyName: "SumQuantity") let queryJoin = DataQuery() .from(NorthwindServiceMetadata.EntitySets.employees) let joinTransform = JoinTransform.join(Employee.orders, alias: "Order") _ = joinTransform.transform(GroupTransform.groupBy(Employee.employeeID, Employee.firstName, Employee.lastName) .aggregate(DataPath.ofDynamic("Order").path(Order.orderID).countDistinct(as: "TotalOrders"))) _ = queryJoin.transform(joinTransform) try self.testApplyQueryResult(query: queryJoin, expectedDynamicPropertyName: "Order") }Declaration
Swift
open func transform(_ items: TransformValue...) -> DataQueryParameters
rest_itemsThe items to be added.
Return Value
This query.
-
The relative URL for this query; a combination of
requestPathandqueryStringif either is non-nil, ornilif the URL is intended to be derived from other properties. Note: It is not recommended for clients to explicitly set the URL, except by using a URL fromEntityValueList.deltaLinkorEntityValueList.nextLink.See also
from,select,expand,filter,orderBy.Declaration
Swift
open var url: String? { get set } -
Set
urlfromdeltaLinkand settrackChangestotrue. Also setdeltaResponsetotrueifdeltaLinkis non-null, otherwisefalse.Declaration
Swift
open func withChangeTracking(deltaLink: String? = nil) -> DataQueryParameters
deltaLinkDelta link (absolute or, preferably, relative to the service root URL).
Return Value
This query.
-
Set
entityKeyto locate an entity by its primary key.Example using proxy classes
open func queryWithKeyExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .withKey(Customer.key(customerID: "QUEEN")) let customer = try service.fetchCustomer(matching: query) self.showCustomer(customer) }Example using dynamic API
open func queryWithKeyExample() throws -> Void { 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 query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet) .withKey(EntityKey() .withProperty(customerIDProperty, value: StringValue.of("QUEEN"))) let customer = try service.executeQuery(query).requiredEntity() self.showCustomer(customer) }Declaration
Swift
open func withKey(_ key: EntityKey) -> DataQueryParameters
keyEntity key.
Return Value
This query.
-
Set
derivedTypeto limit results to a derived complex/entity type.Declaration
Swift
open func withType(_ type: StructureType) -> DataQueryParameters
typeComplex/entity type.
Return Value
This query.
-
Set
url. Note: It is not recommended for clients to explicitly set the URL, except by using a URL fromEntityValueList.deltaLinkorEntityValueList.nextLink.Declaration
Swift
open func withURL(_ url: String?) -> DataQueryParameters
urlQuery URL (absolute or, preferably, relative to the service root URL).
Return Value
This query.