I'm trying to do the equivalent of this SQL Code
SELECT
ID
SUM(CASE WHEN myProperty = 2 THEN 1 ELSE 0 END) as nbRowWithValueOf2,
SUM(CASE WHEN myProperty = 3 THEN 1 ELSE 0 END) as nbRowWithValueOf3
FROM Foo
GROUP BY ID
With Nhibernate.
So far I tried
queryable = queryable
.Select(
Projections.Group<Foo>(c => c.ID),
Projections.Sum<Foo>(c => c.myProperty == MyEnum.Two ? 1 : 0)
Projections.Sum<Foo>(c => c.myProperty == MyEnum.Three ? 1 : 0)
)
But this gives me the following error:
Could not determine member from IIF((Convert(c.myProperty) = 2), 1, 0)
Do you have any idea ?
EDIT 1 : I can get the result with 2 queries but I want to do this in only 1 query.
EDIT 2 : I'm using QueryOver here.