1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
amiry jd
  • 27,021
  • 30
  • 116
  • 215

1 Answers1

2

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.

Dmitry S.
  • 8,373
  • 2
  • 39
  • 49