Book Image

Learning NHibernate 4

Book Image

Learning NHibernate 4

Overview of this book

Table of Contents (18 chapters)
Learning NHibernate 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Identifier generation


We have seen that generator was specified while mapping the identifier. The generator attribute is used to declare the algorithm to be used to generate an identifier value. Value used in the generator attribute is either the short name of algorithm that NHibernate provides out-of-the-box or the assembly qualified name of the NHibernate class that implements the said algorithm. NHibernate has implemented several such algorithms which should fit any identifier generation requirement. But if you are not happy with these then you can build your own algorithm by implementing interface NHibernate.Id.IIdentifierGenerator.

Let's take a look at important identifier generation algorithms that NHibernate offers out-of-the-box.

Identity

This algorithm works on the back of identity columns supported by SQL Server and MySQL. NH will save the entity without assigning any identifier value and database would generate the identifier values before actual database record is saved. NHibernate...