在这里拿出来给大家分享下,希望对大家有帮助,有什么不对或者不好的地方欢迎大家指出来,以为是第一次写希望大家多多包含
public List<VStudent> GetOrderDatas(int index, int count, out int totCount, DateTime? starTime, DateTime? endTime) { List<VStudent> list = null; totCount = 0; using (CET_Entities context = new CET_Entities()) { string num = "select count(*) as num from VStudent where CreateTime >'" + starTime + "' and " + "CreateTime < '" + endTime + "'";//按照时间查询来显示数据量 string query = "SELECT TOP " + count + " * FROM (SELECT ROW_NUMBER() OVER (ORDER BY CreateTime) AS RowNumber,* FROM VStudent where CreateTime >'" + starTime + "' and " + "CreateTime < '" + endTime + "') A WHERE RowNumber > " + count + "*( " + index +"-1"+ ")";//分页查询数据,按照一页10跳数据显示出来 totCount = context.Database.SqlQuery<int>(num).FirstOrDefault(); list = context.Database.SqlQuery<VStudent>(query).ToList(); } return list; }