NHibernate SQL 語句

刪除語句

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 語句。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章