views:

44

answers:

1

We have a single server/single database application that uses NHibernate and Castle ActiveRecord, SQL Server sits behind it.

As part of the processing I need to write as many as 1.2 million rows of data. Using ActiveRecord and NHibernate is woefully slow and needs to be improved - this could easily be done with an "insert into .. select .. from .." probably in a stored proc.

Whats holding me back is the ID generation. We use HiLo generation. If I write a stored proc to do what I need I can get the next number to use from the database table, do my insert and then update the table. The problem is I don't know:

What number(s) NHibernate curently has cached What other operations NHibernate is doing

The best I can do (I think) is to ask NHibernate to refresh its cached numbers when I return from the stored proc - or return the last ID used from the stored proc and update the HiLo cache, but I can't find any references to doing this.

Any ideas ?

+1  A: 

If you haven't, look into using a StateLessSession and setting the batch size. Both of these will considerably speed up bulk data processing.

http://davybrion.com/blog/2008/10/bulk-data-operations-with-nhibernates-stateless-sessions/

Daniel Auger