Skip to content

Local Draft Entity Set

A local-draft entity set is a kind of client-only entity set that uses the entity type defined in the back-end metadata. The entity set defined in the back-end metadata that uses the same entity type is called the draft entity set's active set. And the local-draft entity set is called the backend entity set's draft set. The entity within the draft entity set is called the draft entity. The draft entity can eventually be activated and moved into to the active set using the DataService.activateDraft API.

Defining a Draft Entity Set

Refer to Client-only metadata definition for detailed information.

OData CRUD On a Draft Entity Set

Because the draft entity set and active entity set share the same entity type, the EntityValue.asDraft API is designed to let DataService and OfflineODataProvider know that the entity value is going to be saved into the draft entity set. No special API is required for reading, updating, and deleting a draft entity.

Customer entity = new Customer();
entity.setCustomerID("1");
//create draft entity with EntityValue.asDraft()
eSPMContainer.createEntity(entity.asDraft());

entity = eSPMContainer.getDraftCustomers1WithKey("1");
entity.setCity("test");
//update draft entity
eSPMContainer.updateEntity(entity);

//delete draft entity
eSPMContainer.deleteEntity(entity);
var entity = Customer()
entity.customerID = "1"
//create draft entity with EntityValue.asDraft()
eSPMContainer.createEntity(entity.asDraft())

entity = eSPMContainer.getDraftCustomers1WithKey("1")
entity.city = "test"
//update draft entity
eSPMContainer.updateEntity(entity)

//delete draft entity
eSPMContainer.deleteEntity(entity)
var entity = Customer();
entity.customerID = "1"
//create draft entity with EntityValue.asDraft()
eSPMContainer.createEntity(entity.asDraft())

entity = eSPMContainer.getDraftCustomers1WithKey("1")
entity.city = "test" 
//update draft entity
eSPMContainer.updateEntity(custentityomer);

//delete draft entity
eSPMContainer.deleteEntity(entity);

Refer to EntityValue.asDraft for more details about the API used in the preceding example.

Data Transfer Between Draft EntitySet And Its Active EntitySet

The operation to copy from an active set to a draft set is called "make draft copy", and the operation to move from a draft set to an active set is called "activate draft".

Make Draft Copy

// Read from active entity set
EntityValue entity = eSPMContainer.getCustomerWithKey("1");

// The makeDraftCopy API will make a draft copy of the entity and save it into the draft entity set
EntityValue draftEntity = eSPMContainer.makeDraftCopy(entity.forUpdate());

//now read from the draft entity set
draftEntity = eSPMContainer.getDraftCustomers1WithKey("1");
// Read from the active entity set
var entity = eSPMContainer.getCustomerWithKey("1")

// The makeDraftCopy API will make a draft copy of the entity and save it into the draft entity set
var draftEntity = eSPMContainer.makeDraftCopy(entity.forUpdate())

//now read from the draft entity set
draftEntity = eSPMContainer.getDraftCustomers1WithKey("1")
// Read from the active entity set
let entity = eSPMContainer.getCustomerWithKey("1")

// The makeDraftCopy API will make a draft copy of the entity and save it into the draft entity set
var draftEntity = eSPMContainer.makeDraftCopy(entity.forUpdate())

//now read from the draft entity set
draftEntity = eSPMContainer.getDraftCustomers1WithKey("1")

Refer to DataService.makeDraftCopy and EntityValue.forUpdate for more details about the APIs used in the preceding example.

Activate Draft

If a draft entity value is activated, it will be moved to the active set using POST (or PATCH), and the draft entity value will be deleted from the draft entity set.

EntityValue entity = eSPMContainer.getDraftCustomers1WithKey("1");

//Use EntityValue.withCreate for creating a new entity in the active set
//Use EntityValue.withUpdate for updating an existing entity in the active set
eSPMContainer.activateDraft(item1.withCreate())
var entity = eSPMContainer.getDraftCustomers1WithKey("1")

//Use EntityValue.withCreate for creating a new entity in the active set
//Use EntityValue.withUpdate for updating an existing entity in the active set
eSPMContainer.activateDraft(item1.withCreate())
let entity = eSPMContainer.getDraftCustomers1WithKey("1")

//Use EntityValue.withCreate for creating a new entity in the active set
//Use EntityValue.withUpdate for updating an existing entity in the active set
eSPMContainer.activateDraft(item1.withCreate())

Refer to DataService.activateDraft and EntityValue.withCreate for more details about the APIs used in the preceding example.


Last update: June 15, 2023