请问一下程序中我这样写可以得到正确的结果
IList<Client> results = s.CreateCriteria(typeof(Client)).SetFirstResult(startRowIndex).SetMaxResults(maximumRows).List<Client>();
可是为什么生成的SQL语句竟然还是
select * from client 而不是在数据库端分页,
还需要把数据全部取一下方言用的是:NHibernate.Dialect.SybaseASE15Dialect
谢谢了

解决方案 »

  1.   

    startRowIndex
    maximumRows
    看下这两个的值是否正确
      

  2.   

    “而不是在数据库端分页,还需要把数据全部取一下”最好在数据库进行分页,全部取出,效率很低,占用空间大。给你一个数据库的分页存储过程:
    create proc PageNum
    @PageSize int, --每页显示条数
    @PageIndex int, --当前是第几页
    @totalRows int output, --总行数
    @totalPages int output --总页数
    as
    declare @startId int
    declare @endId int
    set @startId = @PageSize*(@PageIndex-1)+1
    set @endId = @startId+@PageSize-1
    select @totalRows=COUNT(*) from Books
    set @totalPages=@totalRows/@PageSize
    if(@totalRows%@PageSize != 0) --如果总行数除每页显示数据量的值不等于0,则总页数得加1
    begin
    set @totalPages=@totalPages+1
    end
    declare @IndexTable table(Id int identity(1,1) ,nId int)
    insert into @IndexTable select Id from Books
    select * from @IndexTable as t ,Books as b where t.Id>=@startId and t.Id<=@endId and t.nId=b.Id
    go
     
    declare @tr int --总行数
    declare @tp int --总页数
    exec PageNum 4,2,@tr output ,@tp output
    print '这是总页数'+convert(varchar,@tp) --数据转换
    print @tr   
      

  3.   

    To jiuhexuan : 这个没问题找到的原因是说:
    LIMIT and TOP command are not supported by Sybase version < 15
     
    https://hibernate.onjira.com/browse/HHH-2454
    我们用的是 12.5 所以 nhibernate 就直接生成的 select * from table 
      

  4.   

    To sdl2005lyx 你那是 sybase 的语法吗?不好意思, 我sybase 真的不熟
      

  5.   

    请教楼主,在Nhibernate中如何配置 SybaseASE15的连接?