Deleting a Collection with NHibernate Using the Criteria API
- by lomaxx
I think I know what the answer to this question is probably going to be, but I thought I'd go ahead and ask it anyway.
It appears that within NHibernate if I do something like this:
IList<Customer> customers = Session.CreateCriteria(typeof(Customer))
.Add(Restrictions.Eq("Name", "Steve")
.List<Customer>();
And I want to then delete that list of customers. From what I can tell the only way to do it is like this:
foreach(var customer in customers)
{
Session.Delete(customer);
}
But what I'm wondering is if there's any way I can just go:
Session.Delete(customers);
And delete the entire collection with a single call?