Linq to SQL Strange SQL Translation
Posted
by
Master Morality
on Stack Overflow
See other posts from Stack Overflow
or by Master Morality
Published on 2011-02-18T14:49:07Z
Indexed on
2011/02/18
15:25 UTC
Read the original article
Hit count: 240
I have a simple query that is generating some odd SQL translations, which is blowing up my code when the object is saturated.
from x in DataContext.MyEntities
select new
{
IsTypeCDA = x.EntityType == "CDA"
//x.EntityType is a string and EntityType.CDA is a const string...
}
I would expect this query should translate to:
SELECT (CASE WHEN [t0].[EntityType] = @p1 THEN 1 ELSE 0 END) as [IsTypeCDA]
...
Instead I get this :
SELECT
(CASE
WHEN @p1 = [t0].[EntityType] THEN 1
WHEN NOT (@p1 = [t0].[EntityType]) THEN 0
ELSE NULL
END) AS [IsTypeCDA]
...
Since I'm saturating a POCO where IsTypeCDA
is a bool
, it blows up stating I can't assign null
to bool
.
Any thoughts?
Edit: fixed the property names so they make sense...
© Stack Overflow or respective owner