Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can NHibernate save a collection without an iterator?

Simple question: can NHibernate save a collection without an iterator? For example:

var list = new List<Item>();
list.Add(1000 items);

session.Save(list);

Or do I have to do foreach over the list?

like image 553
Daniel T. Avatar asked Dec 18 '09 04:12

Daniel T.


1 Answers

Simple question - simple answer. AFAIK no - you have to iterate. In fact it is faster if you keep flushing and clearing the session time after time like it is told in the NHibernate Docs about batch processing:

for(int i=0;i<list.count;i++)
{
  session.Save(list[i])
  if(i % 20 == 0)
  {
    session.Flush();
    session.Clear()
  }
}
like image 99
zoidbeck Avatar answered Oct 19 '22 07:10

zoidbeck