如何使用 Nhibernate 删除多个数据库实体?
解决这个问题的最佳实践是什么?是否有内置的批处理功能?
示例代码:
using (ITransaction transaction = _session.BeginTransaction())
{
_session.Delete("FROM myObject o WHERE o.Id = IN(1,2,...99999)");
transaction.Commit();
}
提前致谢。
What is the best practice for this problem? Is there any batching features built-in?
Sample code:
using (ITransaction transaction = _session.BeginTransaction())
{
_session.Delete("FROM myObject o WHERE o.Id = IN(1,2,...99999)");
transaction.Commit();
}
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HQL支持IN子句,如果使用setParameterList,甚至可以传入一个集合。
请注意,正如 ddango 在评论中提到的那样,对象中指定的关系级联将不会被执行,因为运行 HQL 查询只是转换为数据库查询,并且实际上不会加载任何实体对象。
HQL supports the IN clause, and if you use setParameterList you can even pass in a collection.
Be aware, like mentioned by ddango in a comment, that relationship cascades specified in your objects will not be executed since running an HQL query simply translates to a DB query and does not actually load any entity objects.
我在获取答案时遇到问题,我发现以下查询有效 100%
客户是类名而不是表名。
id 是小写的,在 HQL 中它是主键而不是类中的属性名称(支持属性名称)
I had problems getting the answer to work and I found the following query worked 100%
Customer is the class name not the table name.
id is lowercase and in HQL it is the Primary Key not a property name in the class (Property names are supported)
您可以使用 HQL 删除多个对象
在这里查找删除- 对于 session.delete 示例
HQL DELETE 示例(您可以将 IN 与 HQL 一起使用):
you can Use HQL to delete multiple objects
Look for delete here - for session.delete example
HQL DELETE example (you can use IN with HQL):