This is a relatively ancient post that says NHib won't auto-increment for you, and proposes a way to do it: http://blog.caraulean.com/2008/08/26/additional-identity-column-with-nhibernate/
If you try it, please post how well it worked out for you. Cheers, Berryl On Jan 31, 10:02 pm, tparvi <[email protected]> wrote: > I need to have counter which starts from 1 and grows by one inside > single production batch. The situation is similar to classic order - > orderlines association. The problem is that it is possible that two > batches are added at the same time but they should have unique id. > > Production Batch 1 > Batch (auto incremented id 1) > Batch (auto incremented id 2) > Production Batch 2 > Batch (auto incremented id 1) > Batch (auto incremented id 2) > Batch (auto incremented id 3) > > In database the ProductionBatch and Batch are separate tables and > there is a foreign key from Batch to ProductionBatch. I have control > over the database so modifying it is not a problem. The transaction > which adds new batches should be pretty fast (adding single row into > databse) so it is not long running operation. Of course I would also > like to avoid situation where I have to deal with deadlocks. > > I'm using NHIbernate 3 with Fluent NHiberate and SQL Server 2008 R2. > What is the best way to create the id for each batch? My initial idea > would store some kind of counter in the ProductionBatch and use row > lock on it. Other approach would be running select for update query > outside nhibernate? -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
