日期:2014-05-18  浏览次数:20783 次

Nhibernate CreateSQLQuery()
SQL code

select c.Id as CategoryId ,max(c.CategoryName) as CategoryName,COUNT(a.id) as Count from Category as c 
    inner join Article as a on c.Id = a.CategoryId 
    where c.type='blog' and a.AccountId = :aId group by c.Id")



使用CreateSQLQuery方法执行上面的sql语句,怎么让执行结果为我自定义的实体 。

------解决方案--------------------
http://blog.csdn.net/canduecho/article/details/4149930
------解决方案--------------------
要返回已映射实体,用 AddEntity,要返回没有映射的自定义类实例,用 SetResultTransformer:

session.CreateSQLQuery(...).SetResultTransformer(...)