Skip to main content

Developing an Application

 

OutSystems

Entities

Entities are elements that allow you to persist information in the database and to implement your database model. You can think of them as database tables or views.

An Entity is defined through Entity Attributes that store the information related to it. Examples of entity attributes are: Name, Address, Zip Code, or City.

Primary Key

In OutSystems, a primary key is called Entity Identifier.

When an Entity is created, an attribute called Id is automatically added as Entity Identifier. By default, it's a Long Integer and its value is automatically calculated in sequence (an AutoNumber in OutSystems). This way, you don't have to implement any specific logic to uniquely identify each entity record.

You can use other data types as Entity Identifiers or switch off the AutoNumber in an attribute. In this cases, you have to implement the logic to uniquely identify each entity record.

To set another attribute as Entity Identifier simply go that attribute, right-click and set it as identifier.

In OutSystems, it is not possible to have composite keys because only one attribute can be the Entity Identifier. But you can use indexes to create alternate keys (see more below about indexes).

Sequential Attributes

Sequential attributes are useful most of the times for Entity Identifier attributes. It's an easy way to ensure that each record has a unique primary key.

When creating new records in the database with Entity Actions, the platform automatically calculates a new sequential and unique value.

There can be only one sequential attribute per Entity.

Indexes

Like in relational databases, OutSystems provides indexes for a faster access to data in the entity. If you usually search or sort by one or more attributes of the entity, you can create an index based on those attributes to make it faster.

Indexes can also be used to create alternate and composite keys.

When creating an index there is always a relevant trade-off between fetching and inserting data as it may bring some overhead to the latter.

Impacts when Changing Entities

When you create a new entity attribute, the platform automatically manages for you the update of all records stored in the database. The new attribute is added to the records and set with the default value for its data type.

When you set an entity attribute as mandatory it is automatically validated on the user interface by the platform. However, in the database, mandatory attributes are created allowing null values thus, at the database level there's no validation for mandatory attributes.

When you delete an entity or an entity attribute, the platform is permissive and let's you do it whether it is being used or not, but you must fix the elements where it is being used. In the database, the entity or entity attribute is not deleted by the platform.

  • Was this article helpful?