Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
Npgsql en EFCore no puede traducir DateTimeOffset.Date

¿Es este el comportamiento esperado? si es así, ¿hay alguna solución? Estoy usando Net Core 5.0 y npgsql 5.0

 public async Task<List<long>> GetGuiaIdsWithFilters(DateTime createddate) { IQueryable<Guia> guiaToReturn = _context.Guia; createddate = createddate.ToUniversalTime(); return await guiaToReturn.Where(g => g.StatusHistory.Any(s.Fecha.Date == createddate.Date)).Select(x => x.Id).ToListAsync(); }

Ejecutar esta consulta devolverá el siguiente error que aislé para que el proveedor no pudiera extraer la parte Fecha: s.Fecha.Date (DateTimeOffset.Date). Leí la documentación y DateTimeOffset se almacenará como timestamptz en PostgreSQL, pero no encontré ninguna limitación en las funciones comunes, como obtener la parte de la fecha.

La expresión LINQ [...] no se pudo traducir. Vuelva a escribir la consulta en un formulario que se pueda traducir

Puedo hacer la siguiente solución que funciona bien, pero parece ser una consulta mucho más ineficiente:

 public async Task<List<long>> GetGuiaIdsWithFilters(DateTime createddate) { IQueryable<Guia> guiaToReturn = _context.Guia; var FromDate = createddate.ToUniversalTime().AddDays(-1); var ToDate = createddate.ToUniversalTime.AddDays(1); return await guiaToReturn.Where(g => g.StatusHistory.Any(s => s.Fecha > FromDate && s.Fecha < ToDate)).Select(x => x.Id).ToListAsync(); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El proveedor Npgsql EF Core actualmente no traduce miembros en DateTimeOffset (consulte https://github.com/npgsql/efcore.pg/issues/473 ).

Tenga en cuenta que se desaconseja usar DateTimeOffset con Npgsql, ya que PostgreSQL no tiene un tipo que le corresponda. DateTimeOffset se asigna a la timestamp with time zone , que en realidad no tiene una zona horaria. Si sus marcas de tiempo también están en UTC, considere usar DateTime con Kind=Utc en su lugar.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!