I was trying to get the following to work (Northwind):
var q1 =
from o in db.Orders
select new {
o.OrderID,
HasRegion = (o.ShipRegion == null) ? true : false
};
var q2 = q1.Where(a => a.HasRegion == true).ToList();
but it blew up with yet another alias error.
Msg 4145, Level 15, State 1, Line 9
An expression of non-boolean type specified in a context where a condition is expected, near 'THEN'.
Msg 102, Level 15, State 1, Line 17
Incorrect syntax near 'LPA_L1'.
this was from the following sql
exec sp_executesql N'
SELECT [LPA_L1].[OrderID], [LPA_L1].[LPFA_5]
FROM
(
SELECT [LPLA_1].[OrderID], CASE WHEN CASE WHEN CASE WHEN
(
[LPLA_1].[ShipRegion] IS NULL
)
THEN 1 ELSE 0 END=1 THEN @LO11 ELSE @LO02 END THEN 1 ELSE 0 END AS [LPFA_5]
FROM [Northwind].[dbo].[Orders] [LPLA_1]
)
LPA_L1 WHERE
(
(
(
(
[LPA_L1].[HasRegion] = @HasRegion3
)
)
)
)
',N'@LO11 bit,@LO02 bit,@HasRegion3 bit',@LO11=1,@LO02=0,@HasRegion3=1
This is interesting also because I was trying to reproduce an error I was having in another piece of work in Northwind, but I got a different error, saying the equivalent of Invalid column name 'HasRegion'. I will see if I can get this one to reproduce in Northwind too, but I havent managed yet.
Thanks!
Ross
BTW: I appreciate that true and false are essentially the wrong way around but you get the idea