NHibernate SQL Server Identity Columns - Use or Not Use

I work with SQL Server, and most tables have identifier columns of type int. And now I just stumbled upon a book that says that this mechanism is not recommended. What are the downsides / pros of using identity columns when using NHibernate as an ORM?

+7
source share
2 answers

I'm not an NHibernate expert, but as I understand it, using identity columns breaks UnitOfWork and causes extra round trips to the database.

Fabio Molo (then NHibernate project manager, I'm not sure if he still has one) has a blog post where he explains this in detail:
Identity: Endless Story

Here is another (longer) blog post with sample code:
NH2.1.0: Generator Behavior Explained

However, note that both blog posts are about three years old and talk about NH 2.1.0, and the current version to date is NH 3.3. But I suppose that the problem described by Fabio still exists today.

+5
source

It doesn't matter if they are an identifier column or not. The role of ORM is to map data objects in the database so as not to dictate the structure / design of the database. I used an implementation with identity columns and it works fine.

+4
source

All Articles