Skip to main content

Data Modelling

info

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

Building a robust data model is fundamental for any application. With Cognibase, defining and managing your domain is straightforward and powerful, allowing for intricate relationships and behaviors that cater to complex applications. This guide will walk you through the process of creating a Cognibase domain.

Understanding Domains

In Cognibase, a domain represents a collection of classes that inherit from the DataItem abstract class. Typically, these classes are grouped within a single .NET assembly. By mapping real-world problems into UML class diagrams, your domain becomes a faithful representation of your application's problem space. Once you've created your domain, it can be plugged into both the Cognibase Server and Client.

Defining Data Classes

Begin by creating classes that inherit from the DataItem abstract class. These classes will form the building blocks of your domain. Each class you define will represent a distinct entity within your application's domain.

[PersistedClass]
public class SampleEntity : DataItem
{
...
}

Attributes and Relationships

For each entity, define the properties or attributes associated with it. These properties can be of basic types or can represent relationships with other entities.

Basic/Scalar Properties

Simple attributes like strings, numbers, and dates are defined using properties in your class.

[PersistedProperty]
public string AttributeName { get => getter<string>(); set => setter(value); }


Relationships

To represent relationships between entities, use DataItemRefList<T> where T is the type of related entity.

[PersistedProperty]
public DataItemRefList<RelatedEntity> RelatedEntities => getList<RelatedEntity>();

Annotations

Cognibase leverages annotations (or attributes) to provide meta-information about the classes and properties within your domain.

  • PersistedClass: Annotate classes with this attribute to mark them as persisted.

  • RuntimeClass: Annotate classes with this attribute to mark them as non persisted / in-memory.

  • PersistedProperty: Annotate properties with this attribute to indicate that they should be persisted.

  • RuntimeProperty: Annotate properties with this attribute to indicate that they should not be persisted (in-memory).