I was looking at this problem more and found another interesting scenarios.
For example this:
var testA = from c in db.Currency
where c.Varchar3Column != "EURO" && c.Varchar3Column != "EUR"
select c
var testB = from c in db.Currency
where !(c.Varchar3Column == "EURO" || c.Varchar3Column == "EUR")
select c
You would expect testA.Count() == testB.Count()
because the logic is same just written in a reverted boolean logic however because of the gap in the truncation detection testA
is zero and testB
is correct. The truncation detection should translate !=
operator into 1=1
instead of 1=0
. You could also think about what < <= => >
should do to get correct results.
And even more - Contains
is actually still broken - the truncation detection is missing.
var arr = new [] { "EURO" };
from c in db.Currency
where arr.Contains(c.Varchar3Column)
select c
Results in:
exec sp_executesql N'
SELECT TOP(@p2) COUNT(*) AS [LPAV_]
FROM [dbo].[CURRENCY] [LPLA_1]
WHERE ( ( ( [LPLA_1].[VARCHAR3_COLUMN] IN (@p3))))',
N'@p2 bigint,@p3 varchar(3)',
@p2=1,
@p3='EUR'
And obviously also this one is going to be a problem if you implement the truncation detection without dealing with the negation because the situation becomes a lot more interesting if arr
contains a mix of correct and incorrect values:
var arr = new [] { "EURO", "EUR", "USD" };
from c in db.Currency
where !arr.Contains(c.Varchar3Column)
select c
I cannot think about a good fix for Contains
but I think !=
should become 1=1
.