amiry jd
amiry jd

Reputation: 27585

Delete multiple objects in NHibernate 3.2

In my Repository I have a method like this:

public int Delete(Expression<Func<TEntity, bool>> predicate) {
    var listToDelete = UnitOfWork.Session.Query<TEntity>().Where(predicate).ToList();
    foreach(var item in listToDelete)
        UnitOfWork.Session.Delete(item);
    return listToDelete.Count;
}

But it seems this method has not a good performance! Have you any suggestion for delete a list of objects (by a predicate) in NHibernate 3.2 please?

Upvotes: 1

Views: 1224

Answers (1)

Dmitry S.
Dmitry S.

Reputation: 8503

Use IStatelessSession to delete or update multiple objects. It will be faster because the identity map will not slow down the session/operations.

You can also use HQL queries for batch operations.

Upvotes: 2

Related Questions