I observe a strange behavior when querying for null field an Entity Framework entity with the Devart DotConnect for PostgreSQL connector.
For example: If I made the 2 following tests:
var test1 = context.blocs.Where(x => x.id_bloc == null); var test2 = context.blocs.Where(x => x.id_bloc == 100);
When checking for EF auto-generated SQL query I obtain the following results:
Result for test1:
{SELECT
CAST(NULL AS int) AS "C1",
CAST(NULL AS varchar) AS "C2",
CAST(NULL AS varchar) AS "C3",
CAST(NULL AS varchar) AS "C4"
FROM ( SELECT 1 AS X) AS "SingleRowTable1"
WHERE true = false}
Result for test2:
{SELECT
"Extent1".id_bloc,
"Extent1".numero,
"Extent1".nom,
"Extent1".titre
FROM "role".bloc AS "Extent1"
WHERE "Extent1".id_bloc = 100}
The result when querying for null field is very strange... I was expecting a result similar to the test 2 result but with an "Extent1".id_bloc IS NULL WHERE clause...
Is it a bug? How can I effectively query for null field?
Where(x => !x.id_bloc.HasValue)? (But honestly I would expect that it will create the same SQL.)id_blocto a nullable type while in the database it isn't? It may decide to create a cheap phoney query when the predicates evaluate tofalsefor sure. What happens if you typeWhere(x => true == false)yourself?