views:

76

answers:

1

I'm using the HiLo generator in my S#rpArchitecture/NHibernate project and I'm performing a large import batch.

I've read somewhere about the possibility to predict the Low values of any new records because they are generated on the client. I figure this means I can control the Low values myself or at least fetch the next Low value from somewhere.

The reason I want to use this is that I want to set relations to other entities I'm about to insert. They do not exist yet but will be inserted before the batch transaction completes.

However, I cannot find information about how to set the Low values or how to get what Low value is up next.

Any ideas?

+1  A: 

You don't need to predict anything to set your relationships. They are set based on the domain model, not the IDs.

The benefit of using HiLo is that the IDs are generated client-side (transparent to you anyway), so the Unit of Work is preserved (no DB writes are done until flush/commit), unlike identity, where inserts are immediate.

Recommended read: http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-explained.html

Diego Mijelshon
Thanks, that made me realize that I shouldn't deal with IDs within the batch and assign entities instead of IDs when making references. Works great.
Sandor Drieënhuizen