Db2DecimalFloatToStringPropertyHandler
A property handler that maps the Db2 DECFLOAT type into a string property that keeps the full precision and the special values.
A property handler that maps the Db2 DECFLOAT type into a string property, which keeps the full precision (up to 34 digits) and the special values (NaN and infinity) of the IEEE 754 decimal floating-point value.
Overview
| Name | Description |
|---|---|
| Class | Db2DecimalFloatToStringPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.Db2 |
| Package | RepoDb.Db2 |
| Implements | IPropertyHandler<object, string> |
| Column type | The Db2 DECFLOAT type |
| Property type | string |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the value returned by the driver into its text form. A DB2DecimalFloat.Null, null and DBNull value is returned as null. |
| Set | Property to database | Converts the text form of a DECFLOAT value into a DB2DecimalFloat, to be written into the column. A null or an empty string 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(Db2DecimalFloatToStringPropertyHandler))]
public string 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 = "1234567890.123456789" });
var measurement = connection.Query<Measurement>(e => e.Id == 1).First();
// measurement.Reading keeps the full precision as text
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Measurement>()
.PropertyHandler<Db2DecimalFloatToStringPropertyHandler>(e => e.Reading);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Measurement, Db2DecimalFloatToStringPropertyHandler>(e => e.Reading, new Db2DecimalFloatToStringPropertyHandler(), true);
Type Level Mapping
To apply the handler to every property of the type string:
PropertyHandlerMapper.Add<string, Db2DecimalFloatToStringPropertyHandler>(new Db2DecimalFloatToStringPropertyHandler(), true);
A type level mapping is process-wide: it is applied to every
stringproperty of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless everystringproperty maps to aDECFLOATcolumn.