I’m trying to insert a large volume of data with NHibernate into a database, and it’s very slow in doing so. I’ve read around it and the suggestion everywhere is to let NH set the identity of the row so that it can batch and not need to call SCOPE_IDENTITY after the insert, however, it’s a brownfield app with a legacy database, so I can’t let NHibernate control the identity of the rows.
Is there any way I can tell NH to just not select scope identity and to just insert the rows into the database? I don’t need it to know about their identity at this time, so it makes little difference whether or not the rows know their identity after the insert, but I’m guessing I can’t just tell Nhibernate not to retrieve the identity in this case?
Using Fluent NH if that’s of any consequence.
Thanks in advance.
NH requires the identity to manage the entities in the cache to identify them. So I don’t think that there is a way around.
You performance problems don’t necessarily be caused by the identity. It may be that you flush the session too many times. Try turning off auto flush to verify it or use a StatelessSession.
An ORM is not very good in large mass operations. You should consider to use something more low-level (like SQL).