/// <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;
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。