从nhibernate hql返回不在映射文件中的对象

时间:2010-11-02 09:32:32

标签: nhibernate orm hql

标题几乎说明了我要做的事情。我有选择案例的nhibernate hql

select application.SubmissionDate, count(candidates)
from Application as application group by application.SubmissionDate

我想将此查询的返回值放入一个名为'CountPerDay'对象的对象(不在nhibernate映射文件中)

class CountPerDay {
public DateTime Date,
public int Count
}

nHibernate是否有一些内置的功能/方法?

1 个答案:

答案 0 :(得分:2)

你应该看一下Ad-hoc mapping的NHibernate:

string hql = @"select application.SubmissionDate as Date, count(candidates) as Count 
               from Application as application 
               group by application.SubmissionDate";

var count = session.CreateQuery(hql)
                   .SetResultTransformer(Transformers.AliasToBean(typeof(CountPerDay)))
                   .List<CountPerDay>();