views:

127

answers:

1

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?

A: 

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()
  }
}
zoidbeck
Thanks. Not much more work, just wondering if it can save me a few lines of code.
Daniel T.