Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

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 operators 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.

Primitive types

The primitive types are relatively standard.

Type

Example

Notes

Whole Numbers

6

C# int

Real numbers

45.678 or 45.678f

C# double

Money

45.678m

C# decimal

Constant null

null

C# null

Boolean constants

truefalse

c# true and false

Single-quoted strings

'A ''quoted'' string'

Pascal-style escaping

Double-quoted strings

"A \"quoted\" string"

C-style escaping

Lists

[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

  • No labels