count

open fun count(): DataQuery

Set {@link com.sap.cloud.mobile.kotlin.odata.DataQuery#countOnly DataQuery.countOnly} to true to request only the number of matching query results.

See Also:

{@link com.sap.cloud.mobile.kotlin.odata.DataQuery#inlineCount() DataQuery.inlineCount}, Requesting the Number of Items in a Collection.

Example using proxy classes:
open fun navigationCountExample(): kotlin.Unit
{
    val service = this.service;
    val customer = service.getCustomer(DataQuery().expand(Customer.orders)
        .top(1));
    val orders = customer.orders;
    val query = DataQuery().load(customer, Customer.orders).count();
    val count = service.executeQuery(query).getCount();
    Assert.isTrue(count == orders.size.toLong(),
        "/Users/home/xmkbuilder/data/jenkins/prod-build7010/w/a1o59enhtx/src/main/xs/examples/example.NorthwindProxyClient.xs:358:9");
}
Example using proxy classes:
open fun collectionCountExample(): kotlin.Unit
{
    val service = this.service;
    val customers = service.getCustomers();
    val query = DataQuery().from(NorthwindServiceMetadata.EntitySets.customers)
        .count();
    val count = service.executeQuery(query).getCount();
    Assert.isTrue(count == customers.size.toLong(),
        "/Users/home/xmkbuilder/data/jenkins/prod-build7010/w/a1o59enhtx/src/main/xs/examples/example.NorthwindProxyClient.xs:335:9");
}
Example using dynamic API:
open fun collectionCountExample(): kotlin.Unit
{
    val service = this.service;
    val customersEntitySet = service.getEntitySet("Customers");
    val customers = service.executeQuery(DataQuery().from(customersEntitySet))
        .getEntityList();
    val query = DataQuery().from(customersEntitySet).count();
    val count = service.executeQuery(query).getCount();
    Assert.isTrue(count == customers.length.toLong(),
        "/Users/home/xmkbuilder/data/jenkins/prod-build7010/w/a1o59enhtx/src/main/xs/examples/example.NorthwindClient.xs:367:9");
}
Example using dynamic API:
open fun navigationCountExample(): kotlin.Unit
{
    val service = this.service;
    val customersEntitySet = service.getEntitySet("Customers");
    val customerEntityType = customersEntitySet.entityType;
    val ordersProperty = customerEntityType.getProperty("Orders");
    val customer = service.executeQuery(DataQuery().from(customersEntitySet)
        .expand(ordersProperty).top(1))
        .getEntityList().first();
    val orders = ordersProperty.getEntityList(customer);
    val query = DataQuery().load(customer, ordersProperty).count();
    val count = service.executeQuery(query).getCount();
    Assert.isTrue(count == orders.length.toLong(),
        "/Users/home/xmkbuilder/data/jenkins/prod-build7010/w/a1o59enhtx/src/main/xs/examples/example.NorthwindClient.xs:394:9");
}

Return

This query.