I am new to Nhibernate, so my query may seem trivial to you.
We generally embed data operation code inside
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
...Code for CRUD operations
transaction.Commit();
}
}
Because we generally BeginTransaction/Commit/Rollback for saving/updating/deleting data,
I wonder if BeginTransaction()
and Commit()
are required even if I am retriving data using
session.Get<T>(id);
or
session.CreateCriteria<T>().List();
Please guide.
Thank you!
No, you can't do data retrieval without transaction; all NH operations are transaction-centric.
Read this article by Ayende Rahien.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With