zoukankan      html  css  js  c++  java
  • NHibernate分页获取,通用条件查询方法

    解决问题:解决UI上使用NHibernate通用查询方法(仅适用于多个条件联合查询)

    第一步:在UI层建立构造条件方法:

            private IList<ICriterion> GetCondition(string customerName = "", string address = "")
            {
                Employee employee = new Employee();
                List<ICriterion> queryConditions = new List<ICriterion>();
                if (!string.IsNullOrEmpty(customerName))
                {
                    queryConditions.Add(new LikeExpression("CustomerName", customerName));
                }
                if (!string.IsNullOrEmpty(address))
                {
                    queryConditions.Add(new LikeExpression("Address", address));
                }
                return queryConditions;

            } 

    第二步:在数据访问层使用条件集合生成NHibernate查询语句:

            private IList<Employee> GetRecord(IList<ICriterion> queryConditions, int pageIndex, int pageSize, string orderField, bool isAscending)
            {
                ICriteria criteria = session.CreateCriteria(typeof(Employee));
                foreach (ICriterion cri in queryConditions)
                {
                    criteria.Add(cri);
                }
                int skipCount = (pageIndex - 1) * pageSize;
                criteria.AddOrder(new Order(orderField, isAscending));
                criteria.SetFirstResult(skipCount).SetMaxResults(pageSize);
                return criteria.List<Employee>();

            } 

  • 相关阅读:
    添加到path的作用
    java post格式发送application/x-www-form-urlencoded
    c# 获取本机ip
    Winform学习(八)——使用setup打包程序
    kubernetes 核心技术-ingress
    ExceptionHandler的执行顺序
    cookie、session、token、jwt详解与sso基本实现原理
    java函数式编程及JDK常用函数式接口
    vue饼图
    vue动态页签
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/2305573.html
Copyright © 2011-2022 走看看