NHibernate.ISession.Flush () takes a long time after Delete () operation

In my application, I would like to clear / delete a table (which is the only one) in my SQLite-DB. I am programming in C #. _session is of type NHibernate.ISession. Here is my code:

string queryFmt = "FROM {0}"; string query = String.Format (queryFmt, typeName); _session.Delete (request);
_session.Flush ();

My example DB has over 5000 records (s3db file is about 750KB in size). The Flush () method takes over 6 minutes. (When I perform a delete operation in SQLite Administrator, it takes less than a second.)

How can I free the table faster?

+2


source to share


2 answers


Use ExecuteUpdate in hql query Here is an example:



using(var session = sessionFactory.OpenSession())
{

    String hqlDelete = string.Format("delete {0} t",typename);
    int deletedEntities = session.CreateQuery( hqlDelete ).ExecuteUpdate();
    session.Close();
}

      

+2


source


If you set nhib to show_sql = true in config, which sql will be output?




After your answer, you will see that nhib is taking so long because it is not typing extra lines.

Ayende has a post explaining this here.

0


source







All Articles