使用NHibernate选择第n行 [英] Select every nth row with NHibernate
问题描述
您将如何使用NHibernate QueryOver,HQL或Criteria实现选择第n行的查询?
How would you implement a query that selects every nth row, with NHibernate QueryOver, HQL or Criteria?
当前,我使用以下T-SQL查询:
Currently I use the following T-SQL query:
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (ORDER BY Id) AS [Row]
FROM [TABLE_NAME]
) x WHERE (x.[Row] % 100) = 0
(感谢 Marc Gravell )
推荐答案
您是否考虑过在交叉联接中使用索引表的解决方案?我的意思是,您的表中的行数与您认为的需要的行数一样,每行的索引列整数从1-n开始.这可以在主数据库中,也许旁边还有一个日期列-这种方法的实用性令人惊讶.然后查询看起来像
Have you considered the solution of using an indexing table in a cross join? What I mean is that you have a table with as many rows as you think you will need with an indexed column of integers going from 1-n in each row. This can be in a master database perhaps with a date column beside it - its amazing how useful this method is. The query would then look like
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (ORDER BY Id) AS [Row]
FROM [TABLE_NAME]
) x INNER JOIN [Index_Table] i ON i.Id*100=x.[Row]
这篇关于使用NHibernate选择第n行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!