An entity is similar to a record, but in addition has an associated key. Entities are typically used to model objects that are persisted and queryable.

An entity key can be defined in-place or refer to a declared key definition. When in-line keys are used, ALFA creates a ‘Key’ type by suffixing the name of the entity.

Multiple assertAll blocks can be specified to perform validation.

entity Flight key( Id : uuid ) {
    Code : string
    Departure : time

A reference to an entity can be declared as a datatype key<T> where T is the name of the entity. key<T> can be thought of as a reference/pointer/foreign key to an entity T.

entity Booking key( Code : string ) {
    Flight : key < Flight > // This contains a reference to a Flight object

entity declarations can use includes to extend its attributes.

entity Employee key EmployeeKey includes Taxpayer {
    Dept : string

key EmployeeKey {
    SSID : string
    Name : string

trait Taxpayer {
    TaxRef : string

A special case of an entity is when it has no key - a keyless declaration, in terms of persistence, it can be considered a singleton.

entity Countries {
    CapitalCities : map< string, string >