Skip to content

Instantly share code, notes, and snippets.

@davybrion
Created September 9, 2012 12:08
Show Gist options
  • Select an option

  • Save davybrion/3684012 to your computer and use it in GitHub Desktop.

Select an option

Save davybrion/3684012 to your computer and use it in GitHub Desktop.
code snippets for "Batching NHibernate's DML statements" post
<class name="CrudTest" table="CrudTest">
<id name="Id" column="Id" type="guid" >
<generator class="assigned" />
</id>
<property name="Description" column="Description" type="string" length="200" not-null="true" />
</class>
private IEnumerable<CrudTest> CreateTestObjects(int count)
{
List<CrudTest> objects = new List<CrudTest>(count);
for (int i = 0; i < count; i++)
{
objects.Add(new CrudTest { Id = Guid.NewGuid(), Description = Guid.NewGuid().ToString() });
}
return objects;
}
var testObjects = CreateTestObjects(10000);
var stopwatch = new Stopwatch();
stopwatch.Start();
using (ITransaction transaction = Session.BeginTransaction())
{
foreach (var testObject in testObjects)
{
Session.Save(testObject);
}
transaction.Commit();
}
stopwatch.Stop();
<property name="adonet.batch_size">5</property>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment