c# - Linq to SQL Strange SQL Translation -
i have simple query generating odd sql translations, blowing code when object saturated.
from x in datacontext.myentities select new { istypecda = x.entitytype == "cda" }
i expect query should translate to:
select (case when [t0].[entitytype] = @p1 1 else 0 end) [istypecda] ...
instead :
select (case when @p1 = [t0].[entitytype] 1 when not (@p1 = [t0].[entitytype]) 0 else null end) [istypecda] ...
since i'm saturating poco istypecda
bool
, blows stating can't assign null
bool
.
any thoughts?
edit: fixed property names make sense...
from x in datacontext.myentities select new { istypecda = x.entitytype == null }
c# interpretation (false) or sql interpretation (null)?
this runs in sql sql interpretation. that's why funky translation - operation return nullable bool.
use query punt nullable bool plain old bool.
from x in datacontext.myentities select new { istypecda = ((bool?)(x.entitytype == "cda")) ?? false }
Comments
Post a Comment