get Optional Entity
Return (nullable) The optional entity value of this result.
- Throws:
-
{@link com.sap.cloud.mobile.kotlin.odata.QueryResultException} if the result does not have the expected type.
- Example using proxy classes:
open fun optionalEntityExample(): kotlin.Unit { val service = this.service; val query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .orderBy(Customer.companyName).top(1); val customer = com.sap.cloud.mobile.kotlin.odata.Single.optional(service.getCustomers(query)); if (customer !== null) { val var_customer = xscript.any.unwrap<Customer>(customer); this.showCustomer(var_customer); } }
- Example using dynamic API:
open fun optionalEntityExample(): kotlin.Unit { val service = this.service; val customersEntitySet = service.getEntitySet("Customers"); val customerEntityType = customersEntitySet.entityType; val customerIDProperty = customerEntityType.getProperty("CustomerID"); val companyNameProperty = customerEntityType.getProperty("CompanyName"); val contactNameProperty = customerEntityType.getProperty("ContactName"); val query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).orderBy(companyNameProperty).top(1); val customer = service.executeQuery(query).getOptionalEntity(); if (customer !== null) { val var_customer = xscript.any.unwrap<EntityValue>(customer); this.showCustomer(var_customer); } }
Return
(nullable) The optional entity value of this result.