Deleting a Collection with NHibernate Using the Criteria API

Posted by lomaxx on Stack Overflow See other posts from Stack Overflow or by lomaxx
Published on 2010-05-01T06:40:58Z Indexed on 2010/05/01 6:47 UTC
Read the original article Hit count: 246

Filed under:

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?

© Stack Overflow or respective owner

Related posts about nhibernate