NHibernate执行原生带sum的sql

可以自行查出想要的字段,并且返回的是model类型,可以点出所有的字段。

但是select 后面的字段名 必须有xml的字段名一模一样。

ISession iSession = null;
string sql = @"select count(1)as id,sum(resouces_top)resouces_top,sum(notice_count)notice_count,sum(onlinetime) as onlinetime from nt_correlation where 条件 ";
IQuery q = iSession.CreateSQLQuery(sql).AddScalar("id", NHibernateUtil.Int32).AddScalar("resouces_top", NHibernateUtil.Int32).AddScalar("notice_count", NHibernateUtil.Int32).AddScalar("onlinetime", NHibernateUtil.Int32).SetResultTransformer(Transformers.AliasToBean(typeof(CorrelationModel)));
IList<CorrelationModel> list = q.List<CorrelationModel>();
原文地址:https://www.cnblogs.com/cang12138/p/5460108.html