tags:

views:

84

answers:

2

What would be the best way to achieve a human readable number,

currently have Identity set to a surrogate key.

have been thinking of identity seed but this would lead to gaps.

If i were to generate within a transaction scope then, would concurrency have an effect ?

Would prefer to avoid DBCC CHECKIDENT trigger.

thanks.

+1  A: 

Basically, there are two optimal id generator strategies for NHibernate: guid.comb and hilo/seqhilo (the latter being available on RDBMS that support sequences)

hilo generates integral IDs which are more readable than GUIDs, so that would be your choice in this case.

Don't worry about the gaps; they are not important.

Diego Mijelshon
surrogate key is being generated via guid.comb,issue is human readable id i.e for customer reference (Purchase order No), gaps would lead to discontinuous orders no's which is generally not good idea from a client perspective.will look into the hilo
kalki
Well, that's new information (the requirement for a *sequential* id). In that case, you are better off using **trigger-identity** and generating the value with a trigger.
Diego Mijelshon
A: 

If you have

  • hard requirements for sequential ids
  • already a surrogate key which does not meet the requirements, and don't want to use sequence or identity

then you need to implement it yourself.

I would most probably write an id-Generator which creates unique, sequential ids. This must use its own session to store the latest id in the database. If you have only a single process, then you can create them in memory.

Stefan Steinegger
well i'am leaning towards this approach, is there a particular reason for suggestion of it's own session ?
kalki
@kalki: sure there is a reason. Many session can concurrently access this id-Generator. It must update (and commit) the database independent of these sessions. It needs its own isolation.
Stefan Steinegger