Data Definition
Attributes
Entities and aspects allow you to define attributes. Depending on the attribute types, they will have different types in code, and different UI components. The available attribute types are as follows.
Basic attribute types
Boolean
The simplest type. The values of this type are true
and false
.
The UI component is a checkbox.
Numeric attributes
These attributes represent a number. These include:
- Integer Represented as Long.
- Decimal Represented as Decimal. (Not the same as float or double)
The UI component is a text field, that accepts numbers.
String attributes
These attributes represent text. Although they are all represented as strings, the UI components differ. These available types are:
- String The UI component is a simple text field.
- Rich-Text Markdown The UI component is a markdown editor.
- Rich-Text HTML The UI component is a HTML editor.
Time attributes
These represent the time. Using this has many advantages compared to using numeric types. These include:
- Date Represented as Date.
- Date and Time Represented as DateTime.
The UI component is a calendar.
Document attribute
The document is used for saving files and linking them to an entity instance. It is represented by an object implementing the IDocument interface.
The UI component is a field, where you can upload a file. You can also browse older versions (called revisions) of this file.
documents in code
Previously mentioned types have a straight-forward approach for changing their values in code.
With the document, it is not as trivial. The document has a list of revisions
that contain the
file name, and it's content in bytes.
To get the file from the document field, the document must have at least one revision. You can check this with:
exampleDocument.HasAnyRevision()
Then you can get the revisions of type IDocumentRevision with GetAllRevisions
or GetLatestRevision
. From this object, you can get the file name and content with .FileName
and .Content
;
To add a file to the document field, construct the IDocumentRevision object, and call
exampleDocument.AddRevision(revision);
document public access
If public access is enabled (per document), anyone with the document URL can access this document. If the document contains private information, this poses a security risk. Therefore it is disabled by default. By default, only an authenticated user in the app can access them.
You can enable this in the attribute settings, by checking the Allow public document access
.
To get the document URL, use:
var url = App.Urls.Documents.Generate(document);
Signature attribute
The signature is a special type of document. The difference is in the UI component, that shows as a drawing board. Working with signatures in code should not be any different from working with other documents.
This is described in more detail in Signature Component.
User
This attribute identifies a user. This can either be a registered user of the app, or a
technical user. All users are accessible at App.Security.Users
as IBusinessUser
objects.
User type
To differentiate between a regular user and a technical one, users have a field called Type
which uses
an enum-like class BusinessUserType
with the following entries:
BusinessUserType.RegularUser
BusinessUserType.TechnicalUser
User context
In Business commands and simple expression, the user context is passed to you. To get the user from
the context, use:
ctx.User
A common use might be deciding if a user should be able to use or see a feature. For this you can check if a user has a specific claim.
ctx.User.HasClaim(App.Security.Claims.Admin)
References
Finally, entities can reference other entities and codebooks.
When setting the data in entity A:
Direct reference ( 1 : 1 )
Creates a reference from one entity A instance to one entity B instance. It does not create a reference back.
Direct Nullable reference ( 1 : 0..1 )
Creates a reference from one entity A instance to at most one entity B instance. It does not create a reference back.
Composition ( 1 : N )
Creates a reference from one entity A instance to a number of entity B instances. The entity B automatically has a new Direct reference to entity A.
Aggregation ( 0..1 : N )
Creates a reference from at most one entity A instances to a number of entity B instances. The entity B automatically has a new Direct Nullable reference to entity A.
Many-To-Many ( M : N )
This adds a reference from a number of entity A instances to a number of entity B instances.
In case you are worried about how the many-to-many relationship is handled, the platform automatically generates a table for a new associative antity in the database.
Codebook
Doesn't reference another entity, but a codebook. It is useful for keeping record of some entity status, and for the state machines.
Codebook Collection
References a number of codebook instances of the same type. Same as a single codebook, but one entity instance can have more codebook entries at once.