FirebirdDecFloatToNullableDecimalPropertyHandler

A property handler that maps the Firebird DECFLOAT types into a nullable decimal property, rejecting values that do not fit.

A property handler that maps the Firebird DECFLOAT(16) and DECFLOAT(34) types into a Nullable<decimal> property.

A decimal cannot hold every DECFLOAT value (34 digits, wide exponent, NaN and infinity), so such values are rejected instead of being silently altered. Use FirebirdDecFloatToStringPropertyHandler to keep them.

Overview

Name Description
Class FirebirdDecFloatToNullableDecimalPropertyHandler
Namespace RepoDb.PropertyHandlers.Firebird
Package RepoDb.Firebird
Implements IPropertyHandler<object, decimal?>
Column type The Firebird DECFLOAT(16) and DECFLOAT(34) types
Property type decimal?

Conversions

Method Direction Description
Get Database to property Converts the value returned by the driver (an FbDecFloat, a decimal, or a string) into a decimal?. null and DBNull are returned as null.
Set Property to database Converts the decimal into an FbDecFloat, keeping its coefficient and scale, to be written into the DECFLOAT column. A null value is written as null.

Exceptions

Exception Thrown When
OverflowException The value is outside of the range of a decimal.
FormatException The value is NaN or infinity.
ArgumentException The type of the value returned by the driver is not supported.

Usability

Bind the handler to the property that maps to a nullable DECFLOAT column.

Attribute

public class Quote
{
    public int Id { get; set; }

    [Map("discount"), PropertyHandler(typeof(FirebirdDecFloatToNullableDecimalPropertyHandler))]
    public decimal? Discount { get; set; }
}

Once bound, the library invokes the handler automatically when the property is read or written.

using (var connection = new FbConnection(connectionString))
{
    connection.Insert(new Quote { Id = 1, Discount = null });
    var quote = connection.Query<Quote>(e => e.Id == 1).First();
    // quote.Discount is null
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Quote>()
    .PropertyHandler<FirebirdDecFloatToNullableDecimalPropertyHandler>(e => e.Discount);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Quote, FirebirdDecFloatToNullableDecimalPropertyHandler>(e => e.Discount, new FirebirdDecFloatToNullableDecimalPropertyHandler(), true);

Type Level Mapping

To apply the handler to every property of the type decimal?:

PropertyHandlerMapper.Add<decimal?, FirebirdDecFloatToNullableDecimalPropertyHandler>(new FirebirdDecFloatToNullableDecimalPropertyHandler(), true);

A type level mapping is process-wide: it is applied to every decimal? property of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless every decimal? property maps to a DECFLOAT column.

See Also