Don't use Native Id Generator with NHibernate

by Scott MIllett 6. February 2011 16:00

I get asked this question a fair bit so I thought I may as well stick it up here so I can refer people to this post in future. If you are using the NHiberante native ID generator — that is, letting your database generate IDs for entities — the database will actually be hit when save is called regardless if you are in a transaction or not. This is because the entity is now part of the unit of work and thus NHibernate needs to give it a valid identity to ensure that any other objects that reference it can be persisted correctly. You can read more about this over on Ayende's blog.

Don't have nightmares
Scott

Tags:

NHibernate

Comments (1) -

2/13/2011 9:15:20 AM #

James Crowley

Scott, does that mean you use guid's for ids everywhere? How does that affect your join performance? Or is everything denormalized? When there's not a sensible natural id I find guid's quite a clumsy form of identifier to use at the client website end too... So would be great to get your thoughts

James Crowley United Kingdom |

Comments are closed

About Me

Hello my name is Scott Millett, this is my blog designed to capture my thoughts on development. You can find out more info on me by checking out my linked in profile below.

View Scott Millett's profile on LinkedIn

Coming soon...

Awards

MVP Logo

ASP.NET MVP
2010-2011

Month List

Powered by BlogEngine.NET 2.0.0.36 - Eco Theme by n3o Web Designers