Skip to content

CastAttribute class

namespace: Serenity.Data.Mapping   assembly: Serenity.Net.Services

Cast expression attribute, which converts a value to one of the types that have an equivalent in all supported databases: Int32, Int64, Decimal with Precision and Scale, String with Size, and Date, which drops the time. Converting a number with a fraction to an integer truncates it in SQL Server and SQLite, while it rounds it in the others. SQLite has no decimal type, so a decimal is a REAL there.

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class CastAttribute : BaseExpressionAttribute
parameter description
expression An expression that returns the value to convert.
type The type to convert to.

Public Members

name description
CastAttribute(…) Cast expression attribute, which converts a value to one of the types that have an equivalent in all supported databases: Int32, Int64, Decimal with Precision and Scale, String with Size, and Date, which drops the time. Converting a number with a fraction to an integer truncates it in SQL Server and SQLite, while it rounds it in the others. SQLite has no decimal type, so a decimal is a REAL there.
Expression { get; } The expression to convert.
Precision { get; set; } The number of digits for Decimal, 18 by default.
Scale { get; set; } The number of digits after the decimal point for Decimal, 2 by default.
Size { get; set; } The number of characters for String, 255 by default.
Type { get; } The type to convert to.
override Translate(…)

Exceptions

exception condition
ArgumentNullException The expression is null.

See Also