博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NHibernate系列学习(三)-条件查询Criteria
阅读量:5287 次
发布时间:2019-06-14

本文共 3749 字,大约阅读时间需要 12 分钟。

1.本笔记主要介绍Criteria的使用

2.效果界面

3.代码详情

namespace KimismeDemo{    public partial class Form3 : Form    {        private ISession session;        private ISessionFactory factory;        private ITransaction trans;        public Form3()        {            InitializeComponent();        }        #region 0.0 初始化NH - private void Form3_Load(object sender, EventArgs e)        private void Form3_Load(object sender, EventArgs e)        {            Configuration config = new Configuration().AddAssembly("Kimisme");            factory = config.BuildSessionFactory();            session = factory.OpenSession();            dgvList.AutoGenerateColumns = false;        }         #endregion        private void tsmiEqual_Click(object sender, EventArgs e)        {            ICriteria criteria = session.CreateCriteria(typeof (Student));            criteria.Add(Expression.Eq("Age", 10));            IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } private void tsmiGreaterThan_Click(object sender, EventArgs e) { ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.Add(Expression.Gt("Age",10)); IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } private void tsmiLessThan_Click(object sender, EventArgs e) { ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.Add(Expression.Lt("Age", 10)); IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } private void tsmiLike_Click(object sender, EventArgs e) { ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.Add(Expression.Gt("Name", "i")); IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } private void tsmiNot_Click(object sender, EventArgs e) { //ICriteria criteria = session.CreateCriteria(typeof(Student)); //criteria.Add(Expression.Not()); //IList
list = criteria.List
(); //dgvList.DataSource = list.ToList(); } private void tsmiIsNull_Click(object sender, EventArgs e) { ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.Add(Expression.IsNull("Name")); IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } private void tsmiMultiQueryNew_Click(object sender, EventArgs e) { ICriteria critera = session.CreateCriteria(typeof (Student)); Student stu =new Student(); stu.Name = "Kim"; stu.Age = 18; critera.Add(Example.Create(stu)); IList
stuList = critera.List
(); dgvList.DataSource = stuList.ToList(); } private void tsmiMultiQueryCriteria_Click(object sender, EventArgs e) { IList stuList = session.CreateCriteria(typeof (Student)) .Add(Expression.Like("Name", "%i%")) .Add(Expression.Between("Age", 17, 19)) .List(); dgvList.DataSource = stuList; } private void tsmiOr_Click(object sender, EventArgs e) { ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.Add(Expression.Or(Expression.Eq("Name","Kim"),Expression.Eq("Name","Lily"))); IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } private void tsmiBetween_Click(object sender, EventArgs e) { ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.Add(Expression.Between("Age",17,18)); IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } private void tsmiIn_Click(object sender, EventArgs e) { ICriteria criteria = session.CreateCriteria(typeof(Student)); criteria.Add(Expression.In("Name",new string[]{ "Kim","Lily"})); IList
list = criteria.List
(); dgvList.DataSource = list.ToList(); } }}

5.代码下载

转载于:https://www.cnblogs.com/kimisme/p/4628833.html

你可能感兴趣的文章
Android平板上开发应用的一点心得——精确适配不同的dpi和屏幕尺寸
查看>>
【转】java 解析 plist文件
查看>>
10款屏幕取色器/颜色拾取工具软件介绍及下载地址(附截图)
查看>>
动态规划01背包问题
查看>>
Loader、CursorLoader、AsyncTaskLoader
查看>>
crm-vue项目上线前对加载速度以及兼容IE的一些方法
查看>>
首页列表显示全部问答,完成问答详情页布局
查看>>
sprintf,你知道多少?
查看>>
Eclipse的常见使用错误及编译错误
查看>>
(转)Oracle EBS 有效银行账户取值 银行科目
查看>>
oc 中使用switch需要注意点
查看>>
认识Caffe与Caffe2
查看>>
Ubuntu系统---“NVIDIA 驱动+CUDA+cuDNN ”之后 OpenCV安装
查看>>
数据结构之最小堆的实现C++版
查看>>
cocos2d-js 遮挡层
查看>>
python学习笔记:模块——xpinyin(拼音)、hashlib(加密)
查看>>
MyEclipse高效开发之必备快捷键技能
查看>>
Linux进程通信之System V共享内存
查看>>
The Six Types of Rails Association
查看>>
本周个人进步要点20160828
查看>>