FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler

A property handler that maps the Firebird TIMESTAMP WITH TIME ZONE type into a nullable DateTimeOffset property.

A property handler that maps the Firebird TIMESTAMP WITH TIME ZONE type into a Nullable<DateTimeOffset> property. The UTC offset is kept, but the name of the time zone is not.

A DateTimeOffset keeps the UTC offset, but it cannot hold the name of the time zone (for example America/New_York). Use an FbZonedDateTime property when the time zone name matters.

Overview

Name Description
Class FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler
Namespace RepoDb.PropertyHandlers.Firebird
Package RepoDb.Firebird
Implements IPropertyHandler<object, DateTimeOffset?>
Column type The Firebird TIMESTAMP WITH TIME ZONE type
Property type DateTimeOffset?

Conversions

Method Direction Description
Get Database to property Converts the value returned by the driver (a DateTimeOffset or an FbZonedDateTime) into a DateTimeOffset? holding the local value and the UTC offset of the time zone. null and DBNull are returned as null.
Set Property to database Passes the DateTimeOffset to the driver, which binds it as a TIMESTAMP WITH TIME ZONE value. A null value is written as null.

Exceptions

Exception Thrown When
InvalidOperationException The UTC offset of the time zone cannot be determined.
ArgumentException The type of the value returned by the driver is not supported.

Usability

Bind the handler to the property that maps to a nullable TIMESTAMP WITH TIME ZONE column.

Attribute

public class Appointment
{
    public int Id { get; set; }

    [Map("ends_at"), PropertyHandler(typeof(FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler))]
    public DateTimeOffset? EndsAt { get; set; }
}

Once bound, the library invokes the handler automatically when the property is read or written.

using (var connection = new FbConnection(connectionString))
{
    connection.Insert(new Appointment { Id = 1, EndsAt = null });
    var appointment = connection.Query<Appointment>(e => e.Id == 1).First();
    // appointment.EndsAt is null
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Appointment>()
    .PropertyHandler<FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler>(e => e.EndsAt);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Appointment, FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler>(e => e.EndsAt, new FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler(), true);

Type Level Mapping

To apply the handler to every property of the type DateTimeOffset?:

PropertyHandlerMapper.Add<DateTimeOffset?, FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler>(new FirebirdZonedDateTimeToNullableDateTimeOffsetPropertyHandler(), true);

A type level mapping is process-wide: it is applied to every DateTimeOffset? property of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless every DateTimeOffset? property maps to a TIMESTAMP WITH TIME ZONE column.

See Also