How to quickly save more than a thousand entries in the database in NHibernate?
- by Anry
I create and retain objects of business class in the loop
for (int i = num.StartNumber; i <= num.EndNumber; i++)
{
var voucher = new Domain.GiftVouchers
{
UniqueNumber = i.ToString(),
Denomination = num.Denomination,
ExpiryDateTime = DateTime.Now
};
voucher.Save();
}
The method of preservation NHibernate
using (ISession session = NHibernateHelper.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
session.SaveOrUpdate(giftVouchers);
transaction.Commit();
}
If you generate 1000 + entries, we have to wait long. How can I increase the speed of this operation?