Skip to main content

Model

The database stores all properties of a business object (record). However, the entire record is not often required. For example, user data may contain dozens of different properties: login, email address, last name, first name, date of birth, and so on, but to display a list of users, only few of these parameters are needed. To improve performance, you should load only necessary properties into Model. Models are used for data manipulations, processing, serialization/deserialization, sending to other services. This data type is not tied to a specific storage and therefore can be transferred between different tiers. Model should be used as a base class for all data types, but it doesn't contain any properties. The RecordModel is a base class for all business objects, that can be identified:

  • Id - record unique identifier. A record may have multiple identifiers (codes, names, external identifiers from other services), but these identifier is required and should be globally unique.
  • Version - record unique version. A record may be modified sometimes. The framework stores all modifications in chronicles. Each record modification gets its own unique version.
  • IsDeleted - indicates if a record is deleted.
  • CreatedAtDateTime - a date and time in UTC format when the record has been created.
  • ModifiedAtDateTime - a date and time in UTC format when the latest record modification occurred.
  • CreatedByUser - a user that created a record.
  • ModifiedByUser - a user that made the latest record modification.
  • SeedRecordSnapshot - if a record doesn't have a stable globally unique identifier, for example it was received from external service, which didn't provide such identifier, you may put original external record snapshot to identify the record.

The ExistedRecordModel is a class that represents a single record modification. A set of existed records grouped by record Id is a log of changes, but it does not contain the changes themselves, they are stored in chronicles. Existed record is immutable. It is automatically created and stored in the main database each time a record has been modified and saved. The record data in the database will be updated (overwritten), and its version (with auxiliary data) will be stored in ExistedRecords storage.

  • Id - record unique identifier. Existed records may share the same Id, but different versions.
  • Version - record unique version.
  • ModifiedAtDateTime - a date and time in UTC format when the latest record modification occurred.
  • IsSeeded - indicates that these record version was saved during seeding process.

The core feature of the Model is Optional type. It allows to optionally load, save and validate a certain property. It indicates if a property or is new, changed and valid.

  • Value - contains a value.
  • IsLoaded - indicates if the value is loaded. If it is not loaded, the Value property will be default. Don't use Value property without checking if is loaded.
  • IsNew - nullable, applicable to record values only. Indicates if a record is new (not saved in a data storage yet). If these property is null, then the new record check wasn't applied.
  • IsChanged - nullable, applicable to record values only. Indicates if a record is changed (saved in a data storage, but with older version). If these property is null, then the changed record check wasn't applied.
  • IsValid - nullable, indicates if the value is valid (passed all validations). If these property is null, then validations where not applied to these value.
  • Validations - contains a list of validations that the value didn't pass. If the value is invalid, then IsValid flag will be False, otherwise it will be True.