Class DataType
The set of data types a Breeze query can refer to, and the conversions between the loosely typed values that arrive in a query and the CLR types an expression needs.
public class DataType
- Inheritance
-
DataType
- Inherited Members
Remarks
Each data type is a named singleton, declared as one of the static fields below. Constructing one registers it, so FromName(string) and FromType(Type) can find it afterwards. The names are part of the wire format - they are what the Breeze client writes into a query - so they cannot be changed without breaking clients.
Constructors
DataType(string)
Create a data type with no CLR type behind it, and register it under its name.
public DataType(string name)
Parameters
namestringThe name used on the wire. FromName(string) looks it up by this.
DataType(string, Type)
Create a data type and register it under both its name and its CLR type.
public DataType(string name, Type type)
Parameters
namestringThe name used on the wire. FromName(string) looks it up by this.
typeTypeThe CLR type it maps to. FromType(Type) looks it up by this.
Fields
Binary
A byte array, sent as base64. The only data type with no CLR type behind it, and so the only one that cannot be coerced.
public static DataType Binary
Field Value
Boolean
A bool.
public static DataType Boolean
Field Value
Byte
An 8-bit unsigned byte.
public static DataType Byte
Field Value
DateOnly
A DateOnly - a date with no time part.
public static DataType DateOnly
Field Value
DateTime
A DateTime.
public static DataType DateTime
Field Value
DateTimeOffset
A DateTimeOffset. A plain DateTime coerces to one.
public static DataType DateTimeOffset
Field Value
Decimal
A decimal.
public static DataType Decimal
Field Value
Double
A double-precision double.
public static DataType Double
Field Value
Guid
A Guid, sent as its string form.
public static DataType Guid
Field Value
Int16
A 16-bit signed short.
public static DataType Int16
Field Value
Int32
A 32-bit signed int.
public static DataType Int32
Field Value
Int64
A 64-bit signed long.
public static DataType Int64
Field Value
Single
A single-precision float.
public static DataType Single
Field Value
String
A string.
public static DataType String
Field Value
Time
A TimeSpan, sent as an ISO 8601 duration such as "PT2H30M".
public static DataType Time
Field Value
TimeOnly
A TimeOnly - a time of day with no date.
public static DataType TimeOnly
Field Value
Methods
CoerceData(object?, DataType?)
Convert value to an object of the dataType
public static object? CoerceData(object? value, DataType? dataType)
Parameters
valueobjectThe value as it arrived, usually a string or a boxed number. Null passes through unchanged.
dataTypeDataTypeThe data type to convert to. Null passes the value through unchanged.
Returns
- object
The value as the data type's underlying CLR type.
CoerceList(IList, Type)
Convert list to IList of itemType. Handles case where itemType is enum and/or nullable.
public static IList CoerceList(IList list, Type itemType)
Parameters
listIListThe values to convert, typically the right-hand side of an 'In' clause.
itemTypeTypeThe element type of the returned list.
Returns
- IList
A new List<itemType> holding the coerced values.
FromName(string)
Look up a data type by the name a client sent.
public static DataType FromName(string name)
Parameters
namestringOne of the names of the static fields above, e.g. "DateTimeOffset".
Returns
- DataType
The matching data type.
Exceptions
- KeyNotFoundException
No data type is registered under that name.
FromType(Type)
Look up the data type for a CLR type. A nullable type resolves to the same data type as the type it wraps.
public static DataType FromType(Type type)
Parameters
typeTypeThe CLR type, which may be a Nullable<T>.
Returns
- DataType
The matching data type.
Exceptions
- KeyNotFoundException
No data type maps to that CLR type - enums and entity types among them.
GetName()
The name this data type is known by on the wire, e.g. "Int32".
public string GetName()
Returns
GetUnderlyingType()
The CLR type this data type maps to, or null for Binary, which has none.
public Type? GetUnderlyingType()