NHibernate criteria construction
Posted
by brianberns
on Stack Overflow
See other posts from Stack Overflow
or by brianberns
Published on 2010-05-18T16:16:54Z
Indexed on
2010/05/18
16:21 UTC
Read the original article
Hit count: 377
I am trying to recreate something like the following SQL using NHibernate criteria:
select Range, count(*) from (
select
case
when ent.ID between 'A' and 'N' then 'A-M'
else 'Other'
end as Range
from Subject
) tbl
group by tbl.Range
I am able to create the inner select as follows:
session.CreateCriteria<Subject>()
.SetProjection(
Projections.Conditional(
Expression.Between("Name", "A", "N"),
Projections.Constant("A-N"),
Projections.Constant("Other")))
.List();
However, I can't figure out how to pipe those results into a grouping by row count. Any suggestions? Thanks.
-- Brian
© Stack Overflow or respective owner