使用Criteria API删除具有NHibernate的集合

使用Criteria API删除具有NHibernate的集合,nhibernate,Nhibernate,我想我知道这个问题的答案可能是什么,但我想我还是会继续问下去 在NHibernate中,如果我这样做: IList<Customer> customers = Session.CreateCriteria(typeof(Customer)) .Add(Restrictions.Eq("Name", "Steve") .List<Customer>

我想我知道这个问题的答案可能是什么,但我想我还是会继续问下去

在NHibernate中,如果我这样做:

IList<Customer> customers = Session.CreateCriteria(typeof(Customer))
                                .Add(Restrictions.Eq("Name", "Steve")
                                .List<Customer>();
foreach(var customer in customers)
{
    Session.Delete(customer);
}
但我想知道的是,我是否有办法:

Session.Delete(customers);

并通过一次调用删除整个集合?

不使用条件,但使用HQL很容易:

session.CreateQuery("delete Customer customer where customer in (:customers)")
       .SetParameterList("customers", customers.ToArray())
       .ExecuteUpdate();
但是你不需要加载它们。您也可以一次完成:

session.CreateQuery("delete Customer where Name = 'Steve'")
       .ExecuteUpdate();