刪除語句
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 語句。