FirebirdDecFloatToDecimalPropertyHandler
A property handler that maps the Firebird DECFLOAT types into a decimal property, rejecting values that do not fit.
A property handler that maps the Firebird DECFLOAT(16) and DECFLOAT(34) types into a decimal property.
A
decimalcannot hold everyDECFLOATvalue (34 digits, wide exponent,NaNand infinity), so such values are rejected instead of being silently altered. Use FirebirdDecFloatToStringPropertyHandler to keep them.
Overview
| Name | Description |
|---|---|
| Class | FirebirdDecFloatToDecimalPropertyHandler |
| 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 0. |
| Set | Property to database | Converts the decimal into an FbDecFloat, keeping its coefficient and scale, to be written into the DECFLOAT column. |
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 DECFLOAT column.
Attribute
public class Quote
{
public int Id { get; set; }
[Map("price"), PropertyHandler(typeof(FirebirdDecFloatToDecimalPropertyHandler))]
public decimal 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 = 19.99m });
var quote = connection.Query<Quote>(e => e.Id == 1).First();
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Quote>()
.PropertyHandler<FirebirdDecFloatToDecimalPropertyHandler>(e => e.Price);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Quote, FirebirdDecFloatToDecimalPropertyHandler>(e => e.Price, new FirebirdDecFloatToDecimalPropertyHandler(), true);
Type Level Mapping
To apply the handler to every property of the type decimal:
PropertyHandlerMapper.Add<decimal, FirebirdDecFloatToDecimalPropertyHandler>(new FirebirdDecFloatToDecimalPropertyHandler(), true);
A type level mapping is process-wide: it is applied to every
decimalproperty of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless everydecimalproperty maps to aDECFLOATcolumn.