Db2DecimalFloatPropertyHandler

A property handler that maps the Db2 DECFLOAT type into a DB2DecimalFloat property that keeps the special values.

A property handler that maps the Db2 DECFLOAT type into a DB2DecimalFloat property. The IEEE 754 decimal floating-point values of DECFLOAT (up to 34 digits, including NaN and infinity) are not always representable by a decimal, whereas DB2DecimalFloat keeps them.

Overview

Name Description
Class Db2DecimalFloatPropertyHandler
Namespace RepoDb.PropertyHandlers.Db2
Package RepoDb.Db2
Implements IPropertyHandler<object, DB2DecimalFloat>
Column type The Db2 DECFLOAT type
Property type DB2DecimalFloat

Conversions

Method Direction Description
Get Database to property Converts the value returned by the driver (a DB2DecimalFloat, a decimal, a double, or a string) into a DB2DecimalFloat. null, DBNull and an empty string are returned as DB2DecimalFloat.Null.
Set Property to database Passes the DB2DecimalFloat to the driver. A DB2DecimalFloat.Null value is written as null.

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 Measurement
{
    public int Id { get; set; }

    [Map("reading"), PropertyHandler(typeof(Db2DecimalFloatPropertyHandler))]
    public DB2DecimalFloat Reading { get; set; }
}

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

using (var connection = new DB2Connection(connectionString))
{
    connection.Insert(new Measurement { Id = 1, Reading = DB2DecimalFloat.Parse("1234567890.123456789") });
    var measurement = connection.Query<Measurement>(e => e.Id == 1).First();
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Measurement>()
    .PropertyHandler<Db2DecimalFloatPropertyHandler>(e => e.Reading);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Measurement, Db2DecimalFloatPropertyHandler>(e => e.Reading, new Db2DecimalFloatPropertyHandler(), true);

Type Level Mapping

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

PropertyHandlerMapper.Add<DB2DecimalFloat, Db2DecimalFloatPropertyHandler>(new Db2DecimalFloatPropertyHandler(), true);

See Also