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.
DuckDbBootstrap registers this handler as the default, type-level handler for every
TimeSpanproperty, so it applies automatically without any attribute or manual mapping. Pass addDefaultHandlers: false toUseDuckDb()to opt out and register your ownTimeSpanhandler instead. This default does not extend toTimeSpan?— see DuckDbTimeOnlyToNullableTimeSpanPropertyHandler for the nullable property, which still requires manual binding.
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
A TimeSpan property against a TIME column works out of the box, since the handler is registered by default.
public class Person
{
public int Id { get; set; }
public TimeSpan WakeTime { get; set; }
}
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();
}
To bind it explicitly instead — for example, after addDefaultHandlers: false — use any of the options below.
Attribute
public class Person
{
public int Id { get; set; }
[Map("wake_time"), PropertyHandler(typeof(DuckDbTimeOnlyToTimeSpanPropertyHandler))]
public TimeSpan WakeTime { get; set; }
}
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);