I want to keep one session, but when I rollback transaction then transaction gets isActive=false, so I can not commit and rollback in next statements by using same transaction. then I need to create new transaction but what is going wrong here ?
var session = NHibernateHelper.OpenSession();/* It returns new session. */
var transaction1 = session.BeginTransaction();
var list1 = session.Query<Make>().ToList(); /* It returs 4 records. */
session.Delete(list1[2]);
/* After Rollback, transaction is isActive=false so I can not commit
* and rollback from this transaction in future. so I need to create new transaction.
*/
transaction1.Rollback();
var transaction2 = session.BeginTransaction();
/* It returns 3 records.
* I am not getting object(which was deleted but after that rollback) here why ?
*/
var list2 = session.Query<Make>().ToList();
Anyone have idea what is going wrong here ? I am not getting deleted object which was rollback.
Flushing means that NHibernate will make sure that all changes are persisted to the DB.
That is, it will make sure that all necessary SQL statements are executed keep session in sync to DB.
ISession will execute the SQL statements needed to synchronize the ADO.NET connection’s state with the state of objects held in memory.
In your case : When the transaction is Rollback, all those changes will be reverted but still the session is not synchronised to DB.
So Session.Flush() will do this.
http://nhibernate.info/doc/nh/en/index.html#manipulatingdata-endingsession