NHibernate: insert multiple items at once
Posted
by Gart
on Stack Overflow
See other posts from Stack Overflow
or by Gart
Published on 2010-05-14T10:31:03Z
Indexed on
2010/05/14
10:34 UTC
Read the original article
Hit count: 323
nhibernate
Hello, all! I am learning NHibernate now and I would like to know is it possible to save multiple objects to 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 here generates many INSERT statements which may be sub-optimal in SQL Server 2008 which allows to include multiple data rows in one INSERT statement.
Is it possible to rewrite this code to make use of this functionality - insert all the data in one operation?
© Stack Overflow or respective owner