Expression Typen
Elements in expression language have types, defined in code as follows:
Properties
take their type from the definition in the metadata (e.g. propertyActive
is a Boolean)Functions
define the result type (e.g. functionCreateGuid()
returns aGUID
)
Marshalling types
Some conversions are straightforward and unlikely to cause issues in either SQL or the local evaluator:
Converting between numeric types
Converting to a string
For example:
If a
String
is expected, aDateTime
will be converted first (to something like"2021-04-20 12:00:00"
).If an
Int
is expected, aString
like"Hello"
cannot be converted and causes an error.
Operator parameters
While many of the Expression Operatoren support various types of arguments, most of them will marshall all parameters to a common type.
If all parameters have the same type, the behavior is well-defined.
If they do not, then the behavior is undefined. This means that the operation may very well work as expected, but that the behavior is not guaranteed.
For all other conversions, consider the following:
The SQL Mapper makes no attempt to marshal the values to the same type. The database is the final arbiter on how it handles an operation that involves unequal types, including throwing an error.
The local evaluator makes a best effort to marshall types for comparison. E.g.
The arithmetic operators will try to convert each parameter to some form of number.
The boolean operators will try to convert each parameter to a Boolean.
The string-concatenation operator will try to convert each parameter to a string.
Use the cast operator to explicitly marshal values to known types to avoid errors.
Basistypen
The primitive types are relatively standard.
Type | Beispiel | XML | Notiz |
---|---|---|---|
Ganze Zahlen |
|
| C# |
Dezimalzahlen |
|
| C# |
Dezimalzahlen (hohe Präzision) |
|
| C# |
null - Konstante |
|
| C# |
Boolsche - Konstanten |
|
| c# |
Zeichenkette mit einfachen Anführungszeichen |
|
| Pascal-style escaping |
Alternative: Zeichenketten können auch in doppelten Anführungszeichen eingeschlossen werden |
| Nicht zulässig in XML. Hier müssen die einfachen Anführungszeichen verwendet werden. | C-style escaping |
Liste |
|
| Item can be any type |
Dates, times, and timespans
A product can work with Datetimes
and Times
and Timespans
in the following ways:
Use a property of type
DateTime
,Date
,Time
, orTimeSpan
(e.g.Birthdate
)Call
CreateDate
,CreateUtcDate
, orCreateTime
(see functions)Use type-casting, e.g.
(DateTime)"2021-04-20 12:00:00"
Use a string, e.g.
2021-04-20 12:00:00
(many functions and operators will convert it, but it's not guaranteed)Return a
DateTime
,Time
, orTimeSpan
from a custom function
Expressions also support some basic math with dates, times, and timespans. In the following, DateTime
and Time
are considered equivalent.
DateTime
+TimeSpan
=DateTime
DateTime
-TimeSpan
=DateTime
DateTime
-DateTime
=TimeSpan
TimeSpan
+TimeSpan
=TimeSpan
TimeSpan
-TimeSpan
=TimeSpan
Guids
A product can work with Guids
in the following ways:
Use a property of type
Guid
Call
CreateGuid("44ED5541-482C-4B7B-8E68-376B37140189")
Use type-casting, e.g.
(Guid)"44ED5541-482C-4B7B-8E68-376B37140189"
Use a string, e.g.
"44ED5541-482C-4B7B-8E68-376B37140189"
(many functions and operators will convert it, but it's not guaranteed)Return a
Guid
from a custom function