DuckDbDateOnlyToNullableDateTimePropertyHandler
A property handler that maps a DuckDB DATE column onto a nullable DateTime? property.
A property handler that maps a DuckDB DATE column onto a nullable DateTime? property.
Overview
| Name | Description |
|---|---|
| Class | DuckDbDateOnlyToNullableDateTimePropertyHandler |
| Namespace | RepoDb.PropertyHandlers.DuckDb |
| Package | RepoDb.DuckDb |
| Implements | IPropertyHandler<object, DateTime?> |
| Column type | The DuckDB DATE type |
| Property type | DateTime? |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the DateOnly value returned by the driver into a DateTime? at midnight. Returns null when the value is not a DateOnly. |
| Set | Property to database | Converts the DateTime? into a DateOnly, to be written into a DATE column. Returns null when the value is null. The time-of-day component is ignored. |
Use DuckDbDateOnlyToDateTimePropertyHandler for a non-nullable
DateTimeproperty.
Usability
Bind the handler to the property that maps to a DATE column.
Attribute
public class Person
{
public int Id { get; set; }
[Map("birth_date"), PropertyHandler(typeof(DuckDbDateOnlyToNullableDateTimePropertyHandler))]
public DateTime? BirthDate { 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, BirthDate = null });
var person = connection.Query<Person>(e => e.Id == 1).First();
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Person>()
.PropertyHandler<DuckDbDateOnlyToNullableDateTimePropertyHandler>(e => e.BirthDate);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Person, DuckDbDateOnlyToNullableDateTimePropertyHandler>(e => e.BirthDate, new DuckDbDateOnlyToNullableDateTimePropertyHandler(), true);