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>();

            } 

  • 相关阅读:
    NVI模式
    C#----接口与多继承
    C#----接口与抽象类
    C#----接口的显式实现
    C# -- 继承规则
    MVC多层架构
    BootStrap2学习日记23---弹出对话框
    APP导航设计九法
    DevExpress Grid使用checkBox选中的方法
    遗漏的SQL语句
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/2305573.html
Copyright © 2011-2022 走看看