如何通过向Nhibernate 3.3.3.4001中的Session.Delete(...)发送查询来删除对象 [英] How delete object by sending query to Session.Delete(...) in Nhibernate 3.3.3.4001
本文介绍了如何通过向Nhibernate 3.3.3.4001中的Session.Delete(...)发送查询来删除对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码块,最终应删除一条记录.
I have the following block of code which should ultimately delete a record.
long id = 81;
SessionInstance.Delete("from Core.Domain.Model.Person as obj where obj.Id =:id", id, NHibernateUtil.Int64);
但是在将Nhibernate版本升级到3.3.3.4001之后,此消息会出现以下异常:
But after upgrade Nhibernate version to 3.3.3.4001, this code has a exception by this message :
字典中不存在给定的键.
The given key was not present in the dictionary.
为什么?
推荐答案
如果要使用位置参数(需要使用),语法会有所不同:
If you want to use positional parameters (which you need to), the syntax is a bit different:
session.Delete("from Product p where p.ProductId = ?", id, NHibernateUtil.Int32);
这篇关于如何通过向Nhibernate 3.3.3.4001中的Session.Delete(...)发送查询来删除对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文