MSSQL2012以后的OFFSET分页

  /// 
    ///分页,使用offset,mssql2012以后有用
    ///  
    /// 如:yydate desc,yytime asc,id desc,必须形成唯一性
    /// 
    /// 
    /// 
    /// 
    public List GetList(  string orderstr, int PageSize, int PageIndex, string strWhere)
    {
        if (!string.IsNullOrEmpty(strWhere))
        {
            strWhere = " where " + strWhere;
        }
        string sql = string.Format(
                "select * from [blog] {0} order by {1} offset {2} rows fetch next {3} rows only",  
                strWhere, 
                orderstr, 
                (PageIndex - 1) * PageSize,
                PageSize
            );
        List list = new List();
        using (var connection = ConnectionFactory.GetOpenConnection())
        {
            list = connection.Query(sql).ToList();
        }
        return list;
    }

你可能感兴趣的:(MSSQL2012以后的OFFSET分页)