NHibernate 中in的使用方法,以及使用sql表达式

  public virtual IList GetEmployeeListByPeriodAndDeptList(IList deptlist, DateTime begin, DateTime end)
        {
            using (ISession session = OpenSession())
            {
                return session.CreateCriteria(typeof(EmployeeInfo)).Add(Expression.In("DeptID", deptlist)).Add(Expression.Sql(string.Format("((emp_state = 100000 and emp_in_date <= '{0}') or (emp_state=100001 and emp_in_date <= '{0}' and emp_lea_date>= '{1}'))", end.ToString("yyyy-MM-dd"), begin.ToString("yyyy-MM-dd")))).List();
            }
        }//sql表达式,相当于sql中的条件表达式

 

posted @ 2012-08-29 22:58  Tom Fan  阅读(249)  评论(0编辑  收藏  举报