मुझे पता है कि बहु भाग लिखने के लिए, मुझे निबर्ननेट में लेनदेन का उपयोग करना चाहिए। हालांकि सरल पढ़ने और लिखने के बारे में क्या (1 भाग) ... मैंने पढ़ा है कि हमेशा लेनदेन का उपयोग करना अच्छा अभ्यास है। क्या यह आवश्यक है?क्या मुझे हमेशा निबर्ननेट में लेनदेन का उपयोग करना चाहिए (यहां तक कि सरल पढ़ने और लिखने के लिए भी)?
क्या मुझे एक साधारण पढ़ने के लिए निम्नलिखित करना चाहिए ?? या क्या मैं सिर्फ तहखाने के सभी हिस्सों को छोड़ सकता हूं?
public PrinterJob RetrievePrinterJobById(Guid id)
{
using (ISession session = sessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
var printerJob2 = (PrinterJob) session.Get(typeof (PrinterJob), id);
transaction.Commit();
return printerJob2;
}
}
}
या
public PrinterJob RetrievePrinterJobById(Guid id)
{
using (ISession session = sessionFactory.OpenSession())
{
return (PrinterJob) session.Get(typeof (PrinterJob), id);
}
}
सरल लेखन के लिए
के बारे में क्या?
public void AddPrintJob(PrinterJob printerJob)
{
using (ISession session = sessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(printerJob);
transaction.Commit();
}
}
}
SO पर शानदार उत्तर: http://stackoverflow.com/questions/1657465/nhibernate-transactions-on-reads –