I'm using BLToolKit as a ORM Mapper.
My problem is, that it generates the wrong SQL.
I have this query:
var qry = from i in s.Query<ChannelDTO>()
join o in s.Query<StorageShelfDTO>() on i.Id equals o.ChannelID into p1
select new {i.Id, n = p1.Count()};
var qry2 = qry;
qry2 = qry2.Where(x => x.n == 0);
Debug.Print("Entrys: " + qry2.ToList().ToString());
which generates this SQL:
SELECT
[x].[Id] as [Id1]
FROM
(
SELECT
(
SELECT
Count(*)
FROM
[WMS_StorageShelf] [t1]
WHERE
[i].[ID] = [t1].[ChannelID]
) as [c1],
[i].[ID] as [Id]
FROM
[WMS_Channel] [i]
) [x]
WHERE
[x].[c1] = 0
which is missing the count field in the outer select!
but when I remove the Condition:
qry2 = qry2.Where(x => x.n == 0);
then the correct SQL is generated.