Show/Hide Toolbars

TMS Aurelius Documentation

Navigation: Database Connectivity

Generate Entities From Existing Database

Scroll Prev Top Next More

TMS Aurelius is an ORM framework which means you need to declare entity classes and map them to the database. If you have an existing database, you have the option to generate those classes automatically from the existing database.


First way this can be achieved is using the great TMS Data Modeler tool. It's a database modeling tool which can import existing database structure to the model, and then generate Delphi source code with TMS Aurelius classes. It's very powerful, with a scripting system to customize the source code output, ability to separate classes by units, among other things.


But if you don't want to use a separate tool, and not even leave Delphi IDE, you can quickly generate entity classes using TAureliusConnection component. Simply configure the database connection on it, then right-click the component and choose "Generate entities from database...".




This will connect to the database, import the existing database structure, and open the export dialog with several options to customize the output source code. You can then select tables to export, choose naming policy for classes and properties, among other options. You can even preview the final source code in the "Preview" tab, before confirming. When you click "Ok" button, a new unit with the declares entities will be created in the same project of TAureliusConnection component.




In "Mapping" tab you can choose the tables to export.

In "Advanced Settings" tab you can use the following options:


Naming options


You can define the default rule for naming classes, property/fields, associations and many-valued associations.


Class name comes from table name, property name comes from database field name. Those are the "base names". For associations you have "Use name from" field which specifies what will be used for the "base name". From the base name, the Format Mask will be applied. The "%s" in the format mask will be replaced by the base name. For example, the defualt Format Mask for class naming is "T%s" which means the class name will be the base name (usually Table Caption) prefixed with "T".


Additionally, some naming options allow you to:


Camel Case: The first character of the base name or any character followed by underling will become upper case, all the other will become lower case. For example, if the base name in model is "SOME_NAME", it will become Some_Name.

Remove underline: All underlines will be removed. "SOME_NAME" becomes "SOMENAME". If combined with camel case, it will become "SomeName"

Singularize: If the base name is in plural, it will become singular. "Customers" become "Customer", "Orders" become "Order". It also applies specified singularization rules for English language (e.g., "People" becomes "Person", etc.).




Data Modeler can also generate a dictionary with metadata for the classes. This dictionary can be used in queries in TMS Aurelius. To generate check "Generate Dictionary". You can also specify:


Global Var Name: Defines the name of Delphi global variable to be used to access the dictionary.




Defines some default behaviors when translating tables/fields into classes/properties. You can override this default behaviors individually for each class/property in the "Mappings" tab.





Association Fetch Mode

The default fetch mode used for associations. Default value is Lazy.

Association Cascade Type

The default cascade definition for associations. Options are "None" (no cascade) and "All but Remove" (all cascade options like save, update, merge, except remove cascade). Default value is None.

Many-Valued Association Fetch Mode

The default fetch mode used for many-valued associations. Default is Lazy.

Map One-to-One Relationship As

Defines how 1:1 relationships will be converted by default. A 1:1 relationship can be converted as a regular association (property) or can be considered an inheritance between two classes. Default value is Association.

Ancestor Class

Specifies the name of the class to be used as base class for all entity classes generated. Default value is empty, which means no ancestor (all classes will descend from TObject)

Dynamic Props Container Name

Specifies the default name for the property that will be a container for dynamic properties. If empty, then by default no property will be created in the class.

Check for Missing Sequences

Defines if exporting must abort (raise an error) if a sequence is not defined for a class. Options are:

If supported by database: if database supports sequences/generators, then raise an error if a sequence is not defined (default)

Always: always raise an error if a sequence is not specified

Never: ignore any sequence check




Defines some other general options for exporting.




Generate Dictionary

Defines if the dictionary will be generated.

Register Entities

When checked, the generated unit will have an initialization section with a call to RegisterEntity for each class declared in the script:




This will make sure that when using the generated unit, classes will not be removed from the final executable because they were not being used in the application.

This option is useful when using the entity classes from a TMS XData server, for example.


Don't use Nullable<T>

By default, non-required columns will be generated as properties of type Nullable<T>. Check this option if you don't want to use Nullable, but instead use the primitive type directly (string, integer, etc.)