Insert 20,000 records with NHibernate
-
I am using NHibernate to insert into a database 20,000 records. I would like to know if a time of 15 sec is good or bad and if my method is the best. The code that inserts is this:
private void btnInsertHuge\_Click(object sender, EventArgs e) { ITransaction tx = null; ISession session = null; try { session = factory.OpenSession(); tx = session.BeginTransaction(); InsertHuge(session); tx.Commit(); } catch (Exception ex) { tx.Rollback(); throw ex; } finally { if (session != null) session.Close(); } } ........................... private void InsertHuge(ISession session) { for (int i = 0; i < 20000; i++) { Person person = new Person(); person.LastName = i.ToString(); person.FirstName = i.ToString(); person.PhoneNb = i.ToString(); Car car = new Car(); car.LicenseNumber = i.ToString(); car.Name = i.ToString(); car.Owner = person; session.SaveOrUpdate(car); } }
NOTE: This is just a test. :)
-
I am using NHibernate to insert into a database 20,000 records. I would like to know if a time of 15 sec is good or bad and if my method is the best. The code that inserts is this:
private void btnInsertHuge\_Click(object sender, EventArgs e) { ITransaction tx = null; ISession session = null; try { session = factory.OpenSession(); tx = session.BeginTransaction(); InsertHuge(session); tx.Commit(); } catch (Exception ex) { tx.Rollback(); throw ex; } finally { if (session != null) session.Close(); } } ........................... private void InsertHuge(ISession session) { for (int i = 0; i < 20000; i++) { Person person = new Person(); person.LastName = i.ToString(); person.FirstName = i.ToString(); person.PhoneNb = i.ToString(); Car car = new Car(); car.LicenseNumber = i.ToString(); car.Name = i.ToString(); car.Owner = person; session.SaveOrUpdate(car); } }
NOTE: This is just a test. :)
As you adding a Car relation to Person, you are actually inserting 40 000 objects (i think ;p)
**
xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
New xacc.ide release RSS feed^**
-
As you adding a Car relation to Person, you are actually inserting 40 000 objects (i think ;p)
**
xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
New xacc.ide release RSS feed^**
Yeah...:doh:you are right...my bad. But the question remains.