DuckDbTimeOnlyToNullableTimeSpanPropertyHandler
A property handler that maps a DuckDB TIME column onto a nullable TimeSpan? property.
A property handler that maps a DuckDB TIME column onto a nullable 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 | DuckDbTimeOnlyToNullableTimeSpanPropertyHandler |
| 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 null when the value is not a TimeOnly. |
| Set | Property to database | Converts the TimeSpan? into a DuckDBTimeOnly, to be written into a TIME column. Returns null when the value is null. Any component beyond microsecond precision (DuckDB’s native TIME resolution) is truncated. |
Use DuckDbTimeOnlyToTimeSpanPropertyHandler for a non-nullable
TimeSpanproperty.
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(DuckDbTimeOnlyToNullableTimeSpanPropertyHandler))]
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 = null });
var person = connection.Query<Person>(e => e.Id == 1).First();
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Person>()
.PropertyHandler<DuckDbTimeOnlyToNullableTimeSpanPropertyHandler>(e => e.WakeTime);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Person, DuckDbTimeOnlyToNullableTimeSpanPropertyHandler>(e => e.WakeTime, new DuckDbTimeOnlyToNullableTimeSpanPropertyHandler(), true);