views:

38

answers:

2

I have a process where I create multiple new entities. I've tried adding them to a collection (doing a .Persist() on them), and then when my collection is ready, trying to commit the transaction.

I've checked to make sure that no database calls are being executed until I call Transaction.Commit(), but once I call commit, I see calls being made for each individual entity.

Is there a way to save an entire collection of same-type entities at once?

+2  A: 

Have you set the batch size?

http://ayende.com/Blog/archive/2006/09/16/BatchingSupportInNHibernate.aspx

in your fluent config try setting the

.AdoNetBatchSize(10)

http://fluentnhibernate.org/api/FluentNHibernate.Cfg.Db/PersistenceConfiguration%602.htm

hope this helps you.

dbones
Note that the capability to perform batching is also dependent on your specific database provider. For example, this is not possible (AFAIK) in SQLite.
fostandy
+2  A: 

Also for inserts if you are using Identity as primary key Nhibernate won't be able to batch inserts.

Sly