c# - entity framework, contains and conditional operators (uses charindex insted of like) -


i have following statement:

l.streamname.contains(vid == user.username ? "live" : "") 

when capture sql on server side translated following sql :

cast(     charindex(         case when ('asdfg' = 'dfghy')              n'live'              else n''          end,         [extent1].[streamname]     ) int) ) > 0 

witch not work since charindex of '' never > 0. bug in ef or there don't understand. tracing other statements i've seen ef translates

l.streamname.contains("") 

into

[extent1].[streamname] '%%' 

and works.

just add filtering conditionally. not try generate like '%%' (actually makes no sense)

if (vid == user.username)    query = query.where(l => l.streamname.contains("live")); 

Comments