Van
Van

Reputation: 1377

NHibernate TooManyRowsAffectedException while trying to delete multiple objects

Basically I'm getting this exception while trying to delete a collection of entities with nHibernate. Below is my code

   public void DeleteAll<T>(IList<T> entities)
   {
      using(var tx = session.BeginTransaction())
      { 
        try
        {
             entities.ForEach(e=>session.Delete(e));
             tx.Commit(); 
        }
        catch(Exception)
        {
             tx.Rollback();
        }
      }
   }

Using hql works without any issue but I'd prefer to stick to the LINQish approach.. Oh and I'm connecting to an Oracle database.

Upvotes: 5

Views: 800

Answers (1)

user2099420
user2099420

Reputation:

You can't delete item by foreach, try for and be careful with index of for, after remove set index --

Upvotes: 1

Related Questions