PostgreSQL TimeOnly + DateOnly

Hi,

I’m using OrmLite with PostgreSQL and hit an issue inserting a POCO with TimeOnly properties mapped to PostgreSQL time columns.

Versions

  • .NET SDK: 10.0.103
  • Target framework: net10.0
  • ServiceStack: 10.0.0
  • ServiceStack.OrmLite: 10.0.0
  • ServiceStack.OrmLite.PostgreSQL: 10.0.0
  • Npgsql: 10.0.3
  • Npgsql.EntityFrameworkCore.PostgreSQL: 10.0.2
  • PostgreSQL: 16

Model

public class SmokeBooking
{
    [AutoIncrement] public int Id { get; set; }

    [CustomField("DATE")]
    public DateOnly AppointmentDate { get; set; }

    [CustomField("time")]
    public TimeOnly ArrivalWindowStart { get; set; }

    [CustomField("time")]
    public TimeOnly ArrivalWindowEnd { get; set; }

    public SmokeBookingStatus Status { get; set; }
    public DateTime CreatedDate { get; set; }
}

public enum SmokeBookingStatus
{
    Booked,
    Attended
}

An LLM suggested using a custom type converter as a workaround, but I wanted to confirm whether that should actually be required.

Given this is a standard TimeOnly property mapped to a PostgreSQL time column, should OrmLite handle the insert automatically? Or is registering a custom converter currently the expected way to use TimeOnly with PostgreSQL time columns?

Thanks

OrmLite already includes a PostgreSqlDateOnlyConverter.cs for DateOnly types and a TimeOnlyConverter.cs for TimeOnly types but this is based on TimeSpanAsIntConverter which persists time as an integer in ticks.

You would need a custom type converter if you want different behavior or to use a different data type.

1 Like