NHibernate: insert multiple elements at once
all! I am learning NHibernate now and I would like to know if it is possible to save multiple objects in the database in one operation.
For example, consider this test code
private static void SaveTestBillNamesInSession(ISession session, params string[] names)
{
var bills = from name in names
select new Bill
{
Name = name,
DateRegistered = DateTime.Now,
};
foreach (var bill in bills)
session.SaveOrUpdate(bill);
}
This loop generates many INSERT statements that might be suboptimal in SQL Server 2008, allowing multiple rows of data to be included in a single INSERT statement.
Can I rewrite this code to use this function - insert all data in one operation?
Update Ok, now he really started shipping everything in one batch. Many thanks to everyone!
+2
a source to share