删除语句
string hql = @"delete from Inventory where OrgId = :OrgId and Id = :Id";
this.Session.CreateQuery(hql)
.SetInt32("OrgId", orgId)
.SetInt32("Id", id)
.ExecuteUpdate();string hql = @"delete from Goods where Id in (:ids)";
return this.Session.CreateQuery(hql)
.SetParameterList("ids", ids)
.ExecuteUpdate();查询语句
string hql = @"from Inventory where OrgId = :OrgId and Status = :Status";
Inventory model = this.Session.CreateQuery(hql)
.SetInt32("OrgId", orgId)
.SetInt32("Status", 1)
.UniqueResult<Inventory>();string hql = @"from Account";
IList<Account> list = this.Session.CreateQuery(hql).List<Account>();return this.Session.QueryOver<Goods>()
.Where(x => x.ErpGoodsCode == code)
.RowCount() > 0;return this.Session.QueryOver<Goods>()
.Where(x => x.ErpGoodsCode == erpCode)
.AndNot(x => x.GoodsStatus == 9)
.Take(1)
.SingleOrDefault();Goods goods = this.Session.QueryOver<Goods>()
.Where(x => x.Id == GoodsId)
.Take(1)
.SingleOrDefault();return this.Session.QueryOver<GoodsImg>()
.Where(x => x.GoodsId == goodsId)
.List();IList<ICriterion> list = new List<ICriterion>();
list.Add(Restrictions.Eq("Name", name));
return this.GetByCriterion(list);修改语句
string hql = @"update Inventory set Status = :Status where OrgId = :OrgId and Id = :Id";
this.Session.CreateQuery(hql)
.SetInt32("Status", -1)
.SetInt32("OrgId", orgId)
.SetInt32("Id", id)
.ExecuteUpdate();另外还有 NHibernate 自带的Add, Save, SaveOrUpdate 语句。
本文介绍了使用NHibernate进行常见的数据库操作,包括增删改查等基本操作,并提供了具体的代码示例。通过这些示例,读者可以更好地理解如何在.NET环境中使用NHibernate框架。
5302

被折叠的 条评论
为什么被折叠?



