xasp wrote:
NHibernate has to send the INSERT to the database, because there's no other way to set the Id of the object (which you might need after the SaveOrUpdate).
Just to clarify that, by default you will probably map 'identity' if you are using SQL Server. This is one of many strategies NHibernate can employ to generate id's automatically.
The problem with 'identity' strategy is that it has to do an INSERT before it will give you an id. So if your mapping has the 'identity' strategy (the default with SQLServer - you've probably got this or 'native') then it must do this. It's no choice. NHibernate is limited by the database's insert strategy.
If you are using Oracle, you can use the 'sequence' generation strategy which doesn't need to do an INSERT to get the next id.
Alternatively, there are other strategies you can use...
You can use GUID id generation, however I'm getting this by looking at a Hibernate book (not NHibernate so I'm not sure if NHibernate implements it).
Altogether, there are about 10 different id generation strategies you can map. 'Identity' is just one. And it's slightly odd by having to do an INSERT before it can provide the id.