Data Centric Functions

Other Data-Centric Functions

When you create a data type in C1 CMS, the system automatically generates the data-centric functions. They are not limited to Get<DataType>Xml and the filter functions (DataReferenceFilter, FieldPredicatesFilter, CompoundFilter, ActivePageReferenceFilter).

Along with Get<DataType>Xml, it also generates three more functions to do CRUD operations on a data type.

  • AddDataInstance
  • UpdateDataInstance
  • DeleteDataInstance

These two functions get references to data items:

  • GetDataReference
  • GetNullableDataReference

AddDataInstance

The AddDataInstance function creates a new instance of a given type. It is a programmatic counterpart of adding a data item to a data type manually.

Most of its parameters match the names and types of the data type’s fields.

It also has or may have a number of system-defined parameters.

  • Id (Guid): The unique ID of the data item to add.
  • PageId (Guid): [Required] The ID of the page a page data folder or metatype are related to. Not applicable to global data types.
  • PublicationStatus (String): The publication status of a data item to add. Only applicable to data types with enabled publication.
  • CultureName (String): The culture name to use when adding a data item. Only applicable to data types with enabled localization.
  • SourceCultureName (String): The source culture name to use when adding a data item. Only applicable to data types with enabled localization.
  • FieldName (String): [Required] The unique name of the meta field to add to the page. Only applicable to page metatypes.

Please note that every time you add a new item with this function, you should generate a new ID. You can use the Composite.Utils.Guid.NewGuid function for that.

The function returns void.

UpdateDataInstance

The UpdateDataInstance function updates one or more instances of a given type with provided values. It is a programmatic counterpart of editing one or more data items manually.

Most of its parameters match the names and types of the data type’s fields.

It also may have a number of system-defined parameters such as PageId (optional here), PublicationStatus, CultureName, SourceCultureName and FieldName (optional here). Please see AddDataInstance for their description.

Besides, it has another system-defined parameter:

  • Filter (Expression<Func<(DataType),Boolean>>): The filter expression to select one or more data items that match the criteria specified.

The function returns void.

DeleteDataInstance

The DeleteDataInstance function deletes one or more instances of a given type based on the filter’s criteria. It is a programmatic counterpart of deleting one or more data items manually.

It has one system-defined parameter:

  • Filter (Expression<Func<(DataType),Boolean>>): The filter expression to select one or more data items that match the criteria specified.

The function returns void.

GetDataReference

The GetDataReference function creates a reference of a specific data type based on a key value of the GUID type passed to it as a parameter.

It has one required parameter:

  • KeyValue (Guid): The key value of the data to reference.

It returns a reference to the item of the data type it is used with.

GetNullableDataReference

The GetNullableDataReference function creates a reference of a specific data type based on a key value of the GUID type passed to it as a parameter; but, unlike GetDataReference, it can return a null reference.

It has one optional parameter:

  • KeyValue (Guid) The key value of the data to reference.

It returns a reference to the item of the data type it is used with, or null, if none can be created.