Entity Framework Is Null, Is Not Null Using DB2

229 Views Asked by At

I tried this:

<pre>var query = this.context.PERFIL_ALERTA.Where(x => x.CodigoEmpresa == EmpresaId && x.IdAtividade == null);<code>

But Entity do this:

SELECT 
CAST(NULL AS decimal(18,2)) AS C1, 
CAST(NULL AS decimal(18,2)) AS C2, 
CAST(NULL AS decimal(18,2)) AS C3, 
CAST(NULL AS varchar(1)) AS C4, 
CAST(NULL AS decimal(18,2)) AS C5, 
CAST(NULL AS decimal(18,2)) AS C6, 
CAST(NULL AS decimal(18,2)) AS C7, 
CAST(NULL AS decimal(18,2)) AS C8, 
CAST(NULL AS varchar(1)) AS C9, 
CAST(NULL AS timestamp) AS C10
FROM  ( SELECT CAST(1 AS int) AS X FROM SYSIBM.SYSDUMMY1 ) AS SingleRowTable1
WHERE CAST('t' AS boolean) = CAST('f' AS boolean)

And Give-me an error:

exception -> ERROR [42846] [CLASS][DB2/NT64] SQL0461N A value with data type "SYSCLASS.VARCHAR" cannot be CAST to type "SYSCLASS.BOOLEAN".

and on debug in DB2:

-- Failed in 355 ms with error: ERROR [42846] [CLASS][DB2/NT64] SQL0461N A value with data type "SYSCLASS.VARCHAR" cannot be CAST to type "SYSCLASS.BOOLEAN".

I have a nullable field on DB2 Table. How Make Is Null Comparison?

On sqlserver works fine...but in db2....

1

There are 1 best solutions below

0
On BEST ANSWER

A colleague at work helped me. My map was wrong. The field idAtividade is nullable. The relation need be optional.

this.HasRequired (T => t.ATIVIDADE)
                 .WithMany (T => t.PERFIL_ALERTAs)
                 .HasForeignKey (T => t.IdAtividade);

correction

this.HasOptional (T => t.ATIVIDADE)
.WithMany (T => t.PERFIL_ALERTAs)
.HasForeignKey (T => t.IdAtividade);