Working with types and default values using Type Shortcuts
The LLBLGen Pro designer works with Type Shortcuts which define a
shortcut (which is a name, e.g.
string) to a .NET type and,
optionally, a default length, precision and / or scale. Type Shortcuts
are an easy way to specify the types for fields in entities, typed views
and the like as they have short, easy to remember names. By default the
designer comes with a set of System Type Shortcuts, which define all
.NET types supported by all supported database drivers and which map to
normal .NET types. System Type Shortcuts are read-only and can't be
Type Shortcuts pane in project settings
Additionally you can define Custom Type Shortcuts which allow you to
define new shortcuts for known .NET types and optionally a default
length, precision and / or scale. Custom Type Shortcuts are modifyable.
This allows you to define e.g. a new
string type, for example
EmailAddress which is a shortcut to
System.String and has a different
default length as the normal
string shortcut, e.g.
When a Type Shortcut is used as the type of a field in e.g. an entity
definition, the default length, precision and scale set for the type
shortcut is used to set the max. length, precision and scale of the
field. This makes it easy to quickly define fields with a specific
characteristic, e.g. a string field with length
100 or a decimal field
3. If the default precision/length/scale is set to
-1, it'll leave the existing value as-is if the field's type is set to that type shortcut. System type shortcuts all values greater or equal than
Editing Type Shortcuts is done in the Project Settings.
Defaults for a type shortcut, per database type
When working Model First, it's sometimes required to be able to specify default values / constraints / preferred database type for a table field. Custom Type Shortcuts make this possible: they allow you to specify default values for a Type Shortcut - Database type (selected from the ones available in the project) combination. This allows you to control what default value is assigned to a target field solely through a type shortcut, so no extra actions have to be taken: defining the type on the entity field is enough.
Additionally they allow the specification of a preferred database type. The LLBLGen Pro designer chooses the best matching database type for a .NET type, but it might be you prefer a different type. The defaults section for a Type Shortcut allows you to do that.
Specifying defaults for a Type Shortcut
To specify a default value or a preferred DB type, first create a custom type shortcut. To do that, open the project
settings and click on the type shortcut tree node. In the custom type
shortcuts tab, add a new custom type shortcut by filling in the top row in the custom type shortcuts grid and pressing
Select the type shorcut and in the section at the bottom called Defaults per database type for selected type shortcut, you can now specify per database type in the project a default value and / or a preferred DB type. It's not required to specify a default value if you just want to specify a preferred DB type, nor is it required to specify a preferred DB type if you just want to specify a default value. When no default value is specified, an existing default value for that database type is removed for that selected type shortcut.
In most cases a default value is not to be used for Identifying / Primary key fields. If you want the default value to be set on Identifying fields which have the type shortcut set as their type, check the Also on PK fields checkbox. If left unchecked, the default value is ignored for PK / Identifying fields and considered empty, so a default value on a PK field is then set to the empty string.
Preferred DB type
By default the preferred DB type is set to Database default. The database default type is the type selected by the logic built into the driver: the selection criteria for the .NET type on the field->DB type plus the sort order per type, which is the way a type was selected in previous versions.
The list of DB types is the complete set of types supported by the driver. It's not pre-filtered with the .NET type of the type shortcut because it might be you want to apply a type converter which performs additional logic.
When a preferred DB type is set, it's used for new fields in tables created through the synchronization feature, and it overrules defined conversions by the driver for the entity field's .NET type. If the chosen preferred db type results in a mapping error, the user has to fix that error manually.
Applying the default value to table fields
When the project is validated and the relational model data is synchronized with the entity model, the target field gets its default value updated if the source field has a Type Shortcut which has a default value defined for that database / driver id. A default value on a table field is always overwritten, if the type shortcut is a custom type shortcut. If the Also on PK fields is not set for a default value, and the field is a PK field, the default value is overwritten with the empty string.