FirebirdDecFloatToStringPropertyHandler

A property handler that maps the Firebird DECFLOAT types into a string property that keeps the full precision and the special values.

A property handler that maps the Firebird DECFLOAT(16) and DECFLOAT(34) types into a string property, which keeps the full precision and the special values (NaN and infinity) of the IEEE 754 decimal floating-point value.

Overview

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

Conversions

Method Direction Description
Get Database to property Converts the value returned by the driver (an FbDecFloat, a decimal, or a string) into its text form. null and DBNull are returned as null.
Set Property to database Passes the text form of the value to the driver, which Firebird converts to DECFLOAT on assignment.

Exceptions

Exception Thrown When
ArgumentException The type of the value returned by the driver is not supported.

Usability

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

Attribute

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

    [Map("price"), PropertyHandler(typeof(FirebirdDecFloatToStringPropertyHandler))]
    public string Price { 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, Price = "1234567890123456789012345678901234" });
    var quote = connection.Query<Quote>(e => e.Id == 1).First();
    // quote.Price keeps every digit as text
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Quote>()
    .PropertyHandler<FirebirdDecFloatToStringPropertyHandler>(e => e.Price);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Quote, FirebirdDecFloatToStringPropertyHandler>(e => e.Price, new FirebirdDecFloatToStringPropertyHandler(), true);

Type Level Mapping

To apply the handler to every property of the type string:

PropertyHandlerMapper.Add<string, FirebirdDecFloatToStringPropertyHandler>(new FirebirdDecFloatToStringPropertyHandler(), true);

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

See Also