Skip to main content

Update

info

This documentation page is heavily under construction. Various information may be missing. Please report any feedback here.

Cognibase offers a seamless experience for updating data items by editing scalar and reference properties and manipulate reference lists.

1. Editing Properties​

Just like with most ORMs, properties of a DataItem can be directly edited. Once edited, Cognibase will automatically detect these changes, ensuring they are included in the transaction that's sent to the server.

// Read item
var key = DataItemKey.Get<Device>("name");
var device = COM.ReadDataItem(key) as Device;

// set name
device.Name = "new name";

In the example above, the Name property of the Device data item is updated to "new name".

2. Managing Reference Properties​

For managing reference properties, you can set a new reference or nullify an existing reference, and Cognibase will detect these changes as well.

// Read item
var key = DataItemKey.Get<Device>("name");
var deviceItem = COM.ReadDataItem(key) as Device;

// creating a new instance to be referenced
var manufacturer = COM.createDataItem<Manufacturer>();
anufacturer.Name = "New Manufacturer";

// Setting a new reference
deviceItem.Manufacturer = manufacturer;

// saving item
COM.Save()

...

// Nullifying a reference
deviceItem.Manufacturer = null;

In this scenario, a new Manufacturer reference is set for the Device data item, and later, this reference is nullified.

3. Manipulating Reference Lists​

Reference lists in Cognibase allow for adding or removing items. These changes are automatically detected.

// Adding an item to a reference list
deviceItem.Components.Add(new Component() { Name = "New Component" });

// Removing an item from a reference list
deviceItem.Components.Remove(specificComponent);

In this example, a new Component is added to the Components reference list of the Device data item, and a specific component is later removed from it.