DuckDbTimeOnlyToTimeSpanPropertyHandler
A property handler that maps a DuckDB TIME column onto a TimeSpan property.
A property handler that maps a DuckDB TIME column onto a TimeSpan property. DuckDB.NET returns a TimeOnly when reading a TIME value, and requires a boxed DuckDBTimeOnly (not a plain TimeSpan) when binding one back as a parameter, so neither direction has a direct TimeSpan equivalent without this handler.
Overview
| Name | Description |
|---|---|
| Class | DuckDbTimeOnlyToTimeSpanPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.DuckDb |
| Package | RepoDb.DuckDb |
| Implements | IPropertyHandler<object, TimeSpan> |
| Column type | The DuckDB TIME type |
| Property type | TimeSpan |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the TimeOnly value returned by the driver into a TimeSpan. Returns default when the value is not a TimeOnly. |
| Set | Property to database | Converts the TimeSpan into a DuckDBTimeOnly, to be written into a TIME column. Any component beyond microsecond precision (DuckDB’s native TIME resolution) is truncated. |
Use DuckDbTimeOnlyToNullableTimeSpanPropertyHandler for a nullable
TimeSpan?property.
Usability
Bind the handler to the property that maps to a TIME column.
Attribute
public class Person
{
public int Id { get; set; }
[Map("wake_time"), PropertyHandler(typeof(DuckDbTimeOnlyToTimeSpanPropertyHandler))]
public TimeSpan WakeTime { get; set; }
}
Once bound, the library invokes the handler automatically when the property is read or written.
using (var connection = new DuckDBConnection(ConnectionString))
{
connection.Insert(new Person { Id = 1, WakeTime = new TimeSpan(6, 30, 0) });
var person = connection.Query<Person>(e => e.Id == 1).First();
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Person>()
.PropertyHandler<DuckDbTimeOnlyToTimeSpanPropertyHandler>(e => e.WakeTime);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Person, DuckDbTimeOnlyToTimeSpanPropertyHandler>(e => e.WakeTime, new DuckDbTimeOnlyToTimeSpanPropertyHandler(), true);