• 使用PetaPoco ORM 框架分页查询



    通过在派生的Repository中调用GetPagingEntities方法来获取分页数据,并返回由PagingDataSet<T>封装分页集合,例如:

    Public PagingDataSet<Student> GetDataPage(int? stuid,int pageIndex, int pageSize )
    {
      return GetPagingEntities(pageSize,pageIndex,CachingExpirationType.ObjectCollection,()=>{
       StringBulider cacheKey = new StringBulider(CacheSetting.GetListCacheKeyPrefix(CacheVersionType.AreaVersion,"stuid",stuid));
       
       if(stuid.HasValue&& stuid.Value>0)
       {
        cacheKey.AppendFormat("stuid-{0}:", stuid.Value);
        
        return stuid.ToString();
        },
        ()=>{
        
         var sql = PetaPoco.Sql.Builder;
         if(stuid.HasValue&& && stuid.Value>0)
          sql.Where("stuid =@0", stuid.Value);
          return sql;
        }
      });
    }
    View Code

             对于查询分为主流查询及非主流查询:

    1)         例如:博客文章列表属于主流查询,博客文章排行属于非主流查询;

    2)         主流查询最大返回记录数限制为PrimaryMaxRecords;

    3)         非主流查询通常不需要查看太多数据,最大返回记录数限制为SecondaryMaxRecords;

    3.         对于查询条件较多的情况可以定义Query类进行封装;

    Public class SampleEntityQuery{
    
      public long? userid=null;
      public SortBySampleEntity sort=SortBySampleEntity.DataCreated;
      
      public enum SortBySampleEntity{
      DateCreate,
      HitTimes
      }
    }
    

     4.         查询语句需要使用PetaPoco.Sql进行组装;

    5.         分页查询结果使用只读集合类型PagingDataSet<T>进行封装,PagingDataSet<T>中含当前集合的PageIndex、PageSize与TotalRecords信息;

  • 相关阅读:
    Python3 collections模块的使用
    基于python的分治法和例题
    docker容器间通信 (共用宿主机)
    HTML之form表单ENCTYPE属性解析
    搭建基于码云gitee平台代码自动部署
    centos7下docker搭建nginx+phpfpm环境
    mysql主从配置
    centos7升级自带mariadb
    linux下安装docker
    centos7安装postgreSql11
  • 原文地址:https://www.cnblogs.com/wisdo/p/4366393.html
Copyright © 2020-2023  润新知