Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
Npgsql in EFCore cannot translate DateTimeOffset.Date

Is this expected behavior? if so, is there any workaround? I'm using Net Core 5.0 and 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();
    }

Running this query will return the following error which I isolated to the provider being unable to extract the Date part: s.Fecha.Date (DateTimeOffset.Date). I read the documentation and DateTimeOffset will be stored as timestamptz in PostgreSQL, but I didn't find any limitations on common functions such as getting the date part.

The LINQ expression [...] could not be translated. Either rewrite the query in a form that can be translated

I can do the following workaround which works fine but it seems to be a much more inefficient query:

    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 Respostas
Responde à pergunta

0

The Npgsql EF Core provider doesn't currently translate members on DateTimeOffset (see https://github.com/npgsql/efcore.pg/issues/473).

Note that it's somewhat discouraged to use DateTimeOffset with Npgsql, since PostgreSQL doesn't have a type that corresponds to it. DateTimeOffset is mapped to PostgreSQL timestamp with time zone, which doesn't actually have a time zone. If your timestamps are also in UTC, consider using DateTime with Kind=Utc instead.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda