La consulta se ejecuta como 1 es igual a 1 en lugar de verificación nula
Frecuentes
Visto 36 veces
0
I am trying to select all the rows where the 'Value' column is null or whitespace. It is of type nvarchar and is allowed nulls.
When executed the following query does not produce the correct sql.
current.Where(
a =>
a.Data.All(ad => ad.AccountTag.Id != currentTag.Item1)
|| a.Data.Any(ad => ad.AccountTag.Id == currentTag.Item1 && string.IsNullOrWhiteSpace(currentTag.Item2)))
The string.IsNullOrWhiteSpace function converts to 1 /* @p3 */ = 1
I've tried using the above function and also using currentTag.Item2 == null || currentTag.Item2.Equals(string.Empty)
both with the same results.
Full SQL below
select data2_.Id from [isnapshot.Client].[dbo].AccountData data2_
where account0_.Id = data2_.ClientAccountId
and data2_.AccountTagId = 1 /* @p2 */
and 1 /* @p3 */ = 1)
1 Respuestas
2
The query is correct. currentTag
is a local variable that has nothing to do with the query. Therefore the expression string.IsNullOrWhiteSpace(currentTag.Item2)
será evaluado antes de que it even is converted to SQL and the result is either true
(1) o false
(0), which will be the value of p3
.
Respondido 28 ago 12, 12:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas .net nhibernate linq-to-sql linq-to-nhibernate or haz tu propia pregunta.
It's only when someone else looks at your code you realise what an idiot you are.
currentTag.Item2
debería haber sidoad.Value
Would never have noticed if you didn't point it out. Thank you - JConstantino@JLevett: Sometimes you are just blind for the most obvious things. It happens to everyone once in a while :-) - daniel hilgarth