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. property Active is a Boolean)

  • Functions define the result type (e.g. function CreateGuid() returns a GUID)

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, a DateTime will be converted first (to something like "2021-04-20 12:00:00").

  • If an Int is expected, a String 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.

  • 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

Type

Beispiel

XML

Notiz

Ganze Zahlen

6

 

C# int

Dezimalzahlen

45.678 oder 45.678f

 

C# double

Dezimalzahlen (hohe Präzision)

45.678m

 

C# decimal

null - Konstante

null

 

C# null

Boolsche - Konstanten

truefalse

 

c# true and false

Zeichenkette mit einfachen Anführungszeichen ''

'A ''quoted'' string'

 

Pascal-style escaping

Alternative: Zeichenketten können auch in doppelten Anführungszeichen eingeschlossen werden ""

"A \"quoted\" string"

Nicht zulässig in XML. Hier müssen die einfachen Anführungszeichen verwendet werden.

C-style escaping

Liste

[A, B, 2, "three"]

 

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 DateTimeDateTime, or TimeSpan (e.g. Birthdate)

  • Call CreateDateCreateUtcDate, or CreateTime (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 DateTimeTime, or TimeSpan 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