OracleIntervalYMPropertyHandler
A property handler that maps the Oracle INTERVAL YEAR TO MONTH type into an OracleIntervalYM property.
A property handler that maps the Oracle INTERVAL YEAR TO MONTH type into an OracleIntervalYM property. As the driver returns the column as a total number of months, this handler exposes the years and months structure.
Overview
| Name | Description |
|---|---|
| Class | OracleIntervalYMPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.Oracle |
| Package | RepoDb.Oracle |
| Implements | IPropertyHandler<object, OracleIntervalYM> |
| Column type | The Oracle INTERVAL YEAR TO MONTH type |
| Property type | OracleIntervalYM |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the value returned by the driver into an OracleIntervalYM. An OracleIntervalYM is returned as is, any other value is treated as the total number of months, and null and DBNull are returned as OracleIntervalYM.Null. |
| Set | Property to database | Passes the OracleIntervalYM to the driver. An OracleIntervalYM.Null value is written as null. |
Usability
Bind the handler to the property that maps to an INTERVAL YEAR TO MONTH column.
Attribute
public class Contract
{
public int Id { get; set; }
[Map("term"), PropertyHandler(typeof(OracleIntervalYMPropertyHandler))]
public OracleIntervalYM Term { get; set; }
}
Once bound, the library invokes the handler automatically when the property is read or written.
using (var connection = new OracleConnection(connectionString))
{
connection.Insert(new Contract { Id = 1, Term = new OracleIntervalYM(2, 6) }); // 2 years and 6 months
var contract = connection.Query<Contract>(e => e.Id == 1).First();
// contract.Term.Years is 2 and contract.Term.Months is 6
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Contract>()
.PropertyHandler<OracleIntervalYMPropertyHandler>(e => e.Term);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Contract, OracleIntervalYMPropertyHandler>(e => e.Term, new OracleIntervalYMPropertyHandler(), true);
Type Level Mapping
To apply the handler to every property of the type OracleIntervalYM:
PropertyHandlerMapper.Add<OracleIntervalYM, OracleIntervalYMPropertyHandler>(new OracleIntervalYMPropertyHandler(), true);