How to quickly save more than a thousand entries in the database in NHibernate?

Posted by Anry on Stack Overflow See other posts from Stack Overflow or by Anry
Published on 2010-04-19T13:37:57Z Indexed on 2010/04/19 13:43 UTC
Read the original article Hit count: 252

Filed under:

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?

© Stack Overflow or respective owner

Related posts about nhibernate