NHibernate - 对列使用自定义sql查询

时间:2010-05-31 21:42:15

标签: nhibernate

有没有办法在NHibernate中使用自定义sql?我想为特定列使用复杂的sql。

示例:

select id, viewsCount, commentsCount, 
  0.2 * viewsCount / (select top 1 viewsCount from articles where isActive = 1 order by viewsCount DESC) as priorityViews, 
  0.8 * commentsCount / (select top 1 commentsCount from articles where isActive = 1 order by commentsCount DESC) as priorityComments, 
  round(0.2 * viewsCount / (select top 1 viewsCount from articles where isActive = 1 order by viewsCount DESC) +  
  0.8 * commentsCount / (select top 1 commentsCount from articles where isActive = 1 order by commentsCount DESC), 1) as priority
from articles

1 个答案:

答案 0 :(得分:2)

您可以使用formula attributeProjections.SqlProjection()

的查询在地图中执行此操作