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)
The query is correct.
currentTagis a local variable that has nothing to do with the query. Therefore the expressionstring.IsNullOrWhiteSpace(currentTag.Item2)will be evaluated before it even is converted to SQL and the result is eithertrue(1) orfalse(0), which will be the value ofp3.