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


1 answer


There is something close to what you want.



If you set the configuration property to a adonet.batch_size

value other than 0 (the default), NHibernate will send multiple SQL Server statements at once.

+7


a source







All Articles