Created
September 9, 2012 12:08
-
-
Save davybrion/3684012 to your computer and use it in GitHub Desktop.
code snippets for "Batching NHibernate's DML statements" post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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