createRelatedEntity

open fun createRelatedEntity(entity: EntityValue, parent: EntityValue, property: Property)

See createRelatedEntity(EntityValue, EntityValue, Property, HttpHeaders?, RequestOptions?).

Parameters

entity

Entity parameter.

parent

Parent parameter.

property

Property parameter.


open fun createRelatedEntity(entity: EntityValue, parent: EntityValue, property: Property, headers: HttpHeaders?)

See createRelatedEntity(EntityValue, EntityValue, Property, HttpHeaders?, RequestOptions?).

Parameters

entity

Entity parameter.

parent

Parent parameter.

property

Property parameter.

headers

Headers parameter.


open fun createRelatedEntity(entity: EntityValue, parent: EntityValue, property: Property, headers: HttpHeaders?, options: RequestOptions?)

Add a pending created entity to the change set, related to a parent entity via a parent navigation property. The entity will be created when this change set is submitted.

Example using proxy classes:
open fun createRelatedEntityInChangeSetExample(): kotlin.Unit
{
    val service = this.service;
    val customers = service.getCustomers(DataQuery()
        .filter(Customer.customerID.equal("ALFKI")));
    val orders = service.getOrders(DataQuery().top(2));
    val changes = ChangeSet();
    val newCustomer = customers.get(0).copy();
    changes.createEntity(newCustomer);
    val firstOrder = orders.get(0).copy();
    val secondOrder = com.sap.cloud.mobile.kotlin.odata.core.ListFunction.last<Order>(orders)
        .copy();
    changes.createRelatedEntity(firstOrder, newCustomer, Customer.orders);
    changes.createRelatedEntity(secondOrder, newCustomer, Customer.orders);
    service.applyChanges(changes);
}
Example using dynamic API:
open fun createRelatedEntityInChangeSetExample(): kotlin.Unit
{
    val service = this.service;
    val customersEntitySet = service.getEntitySet("Customers");
    val ordersEntitySet = service.getEntitySet("Orders");
    val customerEntityType = customersEntitySet.entityType;
    val customerIDProperty = customerEntityType.getProperty("CustomerID");
    val ordersProperty = customerEntityType.getProperty("Orders");
    val customers = service.executeQuery(DataQuery().from(customersEntitySet)
        .filter(customerIDProperty.equal("ALFKI")))
        .getEntityList();
    val orders = service.executeQuery(DataQuery().from(ordersEntitySet).top(2))
        .getEntityList();
    val changes = ChangeSet();
    val newCustomer = customers.first().copyEntity();
    changes.createEntity(newCustomer);
    val firstOrder = orders.first().copyEntity();
    val secondOrder = orders.last().copyEntity();
    changes.createRelatedEntity(firstOrder, newCustomer, ordersProperty);
    changes.createRelatedEntity(secondOrder, newCustomer, ordersProperty);
    service.applyChanges(changes);
}

Parameters

entity

Entity to be created.

parent

Previously created parent entity.

property

Parent's navigation property.

headers

(nullable) Request-specific headers.

options

(nullable) Request-specific options.