/// <summary>
///分页,使用offset,mssql2012以后有用
/// </summary>
/// <param name="orderstr">如:yydate desc,yytime asc,id desc,必须形成唯一性</param>
/// <param name="PageSize"></param>
/// <param name="PageIndex"></param>
/// <param name="strWhere"></param>
/// <returns></returns>
public List<Model.Blog> 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<Model.Blog> list = new List<Model.Blog>();
using (var connection = ConnectionFactory.GetOpenConnection())
{
list = connection.Query<Model.Blog>(sql).ToList();
}
return list;
}
网友评论