npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Translation error when storing NodaTime `(Instant, TimeZoneId)` and filtering on local date time values

thj-dk opened this issue · comments

I'm attempting to achieve the following query using the latest NodaTime and EF Core packages:

select * from "TimeEntries"
where "Date_Instant" at time zone "Date_Tz" >= '2024-06-10'

This is my attempt:

await db.TimeEntries
  .Where(e =>
    e.Date.Instant.InZone(DateTimeZoneProviders.Tzdb[e.Date.Tz]).LocalDateTime > local)
  .ToListAsync();

e.Date.Tz is of course a string representing a Tzdb timezone identifier, e.g. "Pacific/Auckland".

The error returned is "Translation of method 'NodaTime.Instant.InZone' failed."

It this possible or are there better ways to achieve this?

Closed. This already works. My fault.