SqlProjection with alias of joined table?

765 views
Skip to first unread message

bdaniel7

unread,
Apr 7, 2011, 4:24:08 PM4/7/11
to nhusers
Hello,

I have this situation:
public class AnswerSet {
public virtual IList<Answer> Answers {set; get;}
}

session.CreateCriteria<AnswerSet>()
.CreateAlias( "Answers", "a" )
.SetProjection( Projections.ProjectionList()
.Add( Projections.GroupProperty( "TopicId" ), "TopicId" )
.Add( Projections.GroupProperty( "TopicName" ), "TopicName" )
.Add( Projections.SqlProjection( "count (case {a}.numerical_answer
when 1 then 1 when -1 then 1 else null end) as YesAnswers",
new[] { "YesAnswers" }, new IType[] { NHibernateUtil.Int32 } ),
"YesAnswers" )

How can I specify the child collection alias?
{a}.numerical_answer is not working.

The SQL equivalent is

select
[as].topic_id as TopicId
, [as].topic_name as TopicName
, count (case a.numerical_answer
when 1 then 1
when -1 then 1
else null
end) as YesAnswers
from answer_set [as] join answer a on a.answer_set_id = [as].id

Thank you,
Daniel

bdaniel7

unread,
Apr 9, 2011, 8:07:01 AM4/9/11
to nhusers
Reply all
Reply to author
Forward
0 new messages