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

189
Visualizações
Why EF Core generates inverted bit comparison

We are trying to upgrade our project to .net core 5. And now we're struggling with a strange EF behaviour. A simple query:

context.Set<Order>().Where(o => o.Archived == false)

where Order.Archived is bit NOT NULL in the database, generates such a query:

select * from Order where Archived <> CAST(1 as bit)

Why does this happen? We are expecting to have query like the following instead:

select * from Order where Archived = CAST(0 as bit)

Such inversion may prevent proper indices from being used by the database in more complex queries. Is there a way to make EF generate a more straightforward query?

P.S.: We also tried this same approach with nullable fields. And there we do receive the expected query.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I looked into this and for nullable properties it works well, as expected. For non-nullable properties I found this trick, which gives expected result

context.Set<Order>().Where(o => new []{false}.Contains(o.Archived))

In that case we receive following sql query:

select * from Order where Archived = CAST(0 as bit)
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