You use data types in MDriven Designer to define which values an attribute can store and which operations you can perform on that value; this page helps modelers choose an appropriate type before they create data and user interfaces.
What a data type controls
A data type is the classification of an attribute value. It determines:
- Which values the attribute can hold.
- Which operations OCL and EAL can perform on the value.
- How the value is persisted in the database.
- How a ViewModel can present and edit the value.
For example, an attribute named IsPaid should be a Boolean, because it has two meaningful values: true and false. An attribute named Amount should be numeric, so that expressions can add, compare, and calculate with it.
Common attribute types
MDriven commonly uses the following native attribute types.
| Type | Use it for | Example |
|---|---|---|
String
|
Text with a size limit in the database. | A customer's Name can contain "Ava Nilsson".
|
Text
|
Text that does not have a size limit in the database. | An ArticleBody can contain several paragraphs.
|
Integer
|
Whole numbers. | Quantity can be 3.
|
Double
|
Numeric values where a double-precision floating-point value is appropriate. | Latitude can be 59.3293.
|
Decimal
|
Decimal numeric values, commonly amounts and other values where you need decimal precision. | UnitPrice can be 19.95.
|
Boolean
|
A true/false state. | IsActive can be true.
|
DateTime
|
A date and time value; also use this type when the user edits a date. | OrderDate can represent 2026-07-28.
|
TimeSpan
|
A time value or time component edited independently. | StartTime can represent 09:30.
|
Guid
|
A globally unique identifier. | An integration identifier can hold a GUID value. |
Blob
|
Binary data as a byte array. | Attachment can hold uploaded binary content.
|
Choose the type from the meaning of the value
Choose a type based on what the value means, not only on how it looks on screen.
- Use
Booleanfor a yes/no condition. Do not store"Yes"and"No"in a string when the value is a state. - Use
Integerwhen fractions are not valid. For example, a number of attendees is12, not12.5. - Use
Decimalfor an amount such asInvoiceTotal. Do not represent an amount as text, because text cannot participate directly in numeric calculations. - Use
DateTimefor a date the user edits, even when only the date is relevant. UseTimeSpanwhen you need the time part in isolation. See Date vs Time. - Use
Stringfor bounded text such as a name or code. UseTextfor longer content such as notes or an article body. - Use
Blobonly for binary content. Configure the blob's intended content through BlobType.
For a database-generated GUID in persistence mapping, see AutoGuid.
Text values
String and Text both represent text, but they have different persistence intent:
- Choose
Stringwhen the value has a database size limit. Examples includeFirstName,CountryCode, andExternalReference. - Choose
Textwhen the content can be long or its length is not bounded. Examples includeInternalNotesandDescription.
The type determines the stored value; the rendered HTML input type is a separate concern. See Column.Texttype.
Numbers and numeric expressions
Numeric types include Integer, Double, and Decimal. They support arithmetic, but assignments between different numeric types may require conversion and may change precision or discard fractions.
For example, this assignment needs a conversion when the receiving attribute is Decimal and the source is Double:
self.PaymentMenuRequest.VatPercent:=vTypAvBiljett.BiljettPrisMoms.todouble
An explicit conversion documents the intended target type. Converting to a simpler type can lose the fractional part. For example, Decimal.create(5.4).ToInt32 creates a decimal value and converts it to a 32-bit integer, losing .4.
Use the numeric conversion operators described in Number conversions. When EAL needs a Decimal value that cannot be expressed as text, create it explicitly; see Creating numeric types.
Dates and times
A date and a time are not interchangeable values. Model the value that your application needs to edit and calculate with:
- Use
DateTimefor a date entered by a user, such as a delivery date. - Use
TimeSpanwhen the time part is edited independently, such as an opening time.
For example, use DeliveryDate : DateTime for a delivery date and OpeningTime : TimeSpan for a daily opening time. For the detailed choice and rationale, see Date vs Time.
Objects, collections, and custom structures
A class defines a custom business type. An object is an instance of that class. For example, an Order class can have attributes such as OrderDate and IsPaid, and it can be associated with a Customer object.
Use classes and associations to model related business data. For example, model an order's lines as associated OrderLine objects rather than trying to store a list of line values in one text attribute. This gives each line its own attributes, such as Quantity : Integer and UnitPrice : Decimal.
The general programming concepts of structure and pointer types are not available as MDriven OCL data types. Model the required structure with classes, attributes, and associations instead.
Change a type with care
Changing an existing attribute type can affect stored data, expressions, and ViewModels. Test a conversion before making it permanent.
For example, if an existing Price : Integer must become a decimal amount, create a derived attribute that converts the old value and verify it in the relevant ViewModels. After you have verified the result, use the supported conversion approach to make the intended attribute name available without unnecessary ViewModel changes.
See Attribute or Data Type Conversion for derived attributes, explicit transformations, and the FormerNames approach.
Example: model an order line
The following attributes use types that match their business meaning:
| Attribute | Type | Reason |
|---|---|---|
ProductName
|
String
|
A bounded product name. |
Quantity
|
Integer
|
A count of ordered units. |
UnitPrice
|
Decimal
|
An amount that can include a fractional part. |
IsBackordered
|
Boolean
|
A true/false order state. |
RequestedDeliveryDate
|
DateTime
|
A user-entered date. |
CustomerComment
|
Text
|
A potentially long comment. |
See also
- Documentation:Types, images, value stores, pick lists
- Documentation:Number conversions
- Documentation:Creating numeric types
- Documentation:Date vs Time
- Documentation:Attribute or Data Type Conversion
[[Category:Attributes and data types [Beginner]]
