Show/Hide Toolbars

TMS XData Documentation

Navigation: Entity Model

Aurelius Equivalence to Entity Model

Scroll Prev Top Next More

When you create the XData server module, the Entity Model (EM) is automatically created from the current Aurelius mapping, using a default entity model builder, and you don't need to define it yourself. This topic describes the rules used by the model builder to create the model based on Aurelius mapping.


Note that the XData server module creates the EM based on a TMappingExplorer object, which contains all the Aurelius mapping information.


Classes become entity types

Every mapped class in Aurelius becomes an entity type. By default, the name of entity type is the class name. So, if for example your mapping has classes TCustomer, TOrder and TCountry, each of those classes become an entity type in the EM.


Entity sets

XData creates an entity set for each entitytype, so that all entities can be easily accessible from the server. The entity set associated with the class contains all entities (objects) of that class. By default the name of the entity set is the name of the entity type associated to it. Thus, if you have a mapped class named "TCustomer", XData will define an entity type "Customer" in the EM, and will also define an entity set "Customer" that represents all entities of that type. You can prevent the "T" from being removed from class name by using the entity model builder.



Every mapped property or field in an Aurelius class becomes either a property or navigation property in the entity type. If the class property/field is an association, it becomes a navigation property. If it's a scalar property, it becomes a single property. It's important to note that only mapped class members become an entity type property. The name of the property in the EM will be the name of the mapped class property or the name of mapped class field with the "F" prefix removed. As an example, consider the following Aurelius mapping:




  TCustomer = class

  strict private

    FId: Integer;

    FName: string;


    FSex: Nullable<TSex>;

    [Column('BIRTHDAY', [])]

    FBirthday: Nullable<TDate>;

    FCountry: TTC_Country;

    [Column('Description', [])]

    FDescription: TBlob;


    FPhoto: TBlob;


    FPhoto2: TBlob;


    property Id: Integer read FId write FId;

    property Name: string read FName write FName;

    [Column('SEX', [])]

    property Sex: Nullable<TSex> read FSex write FSex;

    property Birthday: Nullable<TDate> read FBirthday write FBirthday;

    property Country: TCountry read FCountry write FCountry;

    property Description: TBlob read FDescription write FDescription;

    [Column('Photo', [TColumnProp.Lazy])]

    property Photo: TBlob read FPhoto write FPhoto;

    property Photo2: TBlob read FPhoto2 write FPhoto2;



The above class will become an entity type named "TCustomer", with the following named properties: Id, Name, Birthday, Country, Description, Sex and Photo. Fields like FId and FName are considered because the class is marked with [Automapping] attribute, so all fields are included (with "F" prefix removed). Also, properties Sex and Photo are also included because they are explicitly mapped. Finally, fields FSex, FPhoto and FPhoto2 are not included because they were excluded from Aurelius mapping because of the [Transient] attribute usage. You can prevent the "F" from being removed of field names by using the entity model builder.

All properties will be created as simple properties, except "Country" which will be a navigation property associated with the "TCountry" that is also an entity type created from TCountry class.