NHibernate SQL 语句

来源:互联网 发布:韩后 知乎 编辑:程序博客网 时间:2024/06/06 03:09

删除语句

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 语句。

0 0
原创粉丝点击