with Key
Set {@link com.sap.cloud.mobile.kotlin.odata.DataQuery#entityKey DataQuery.entityKey} to locate an entity by its primary key.
- Example using proxy classes:
open fun queryWithKeyExample(): kotlin.Unit { val service = this.service; val query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .withKey(Customer.key("QUEEN")); val customer = service.getCustomer(query); this.showCustomer(customer); }
- Example using dynamic API:
open fun queryWithKeyExample(): 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) .withKey(EntityKey() .withProperty(customerIDProperty, StringValue.of("QUEEN"))); val customer = service.executeQuery(query).getRequiredEntity(); this.showCustomer(customer); }
Return
This query.
Parameters
key
Entity key.