Sorry for my question but I need any answer. How do I reserve one id in database without inserting the record?
Asked
Active
Viewed 164 times
0
-
Which id generator are you using? – Stefan Steinegger Nov 11 '10 at 13:42
2 Answers
1
This may be helpful for your needs. I'm not sure if there's a way to reserve an Id through NHibernate, but the idea behind the Hi/Lo approach in that link is to split the Id into two values and allow a client to work disconnected by reserving an entire range of values, thus being able to set its own keys before inserting (re-syncing).
1
I don't know what id generator you use and what problem you actually need to solve. Roughly, this are your options:
- insert a placeholder (null-object)
- use Guids instead (guid.comb), you won't get into this problem at all.
- write your own IdentityGenerator which allows reserved ids (there are again many possibilities to implement this, it depends on your needs)

Stefan Steinegger
- 63,782
- 15
- 129
- 193
-
Definitely be careful with using Guids as primary keys. SQL can run into performance issues there. They definitely make sense, but work with the DBA and know what you're getting into. – David Nov 11 '10 at 14:08
-
@David: Guid.comb fixes some of them (it generates sequential guids). Guids are of course larger then numbers. I'm using bigint for now, which are still half the size of a guid. But I'm not a dba... – Stefan Steinegger Nov 11 '10 at 14:13