What is the best way to perform identity like inserts with out identity enabled?

Posts   
 
    
Posts: 112
Joined: 09-Aug-2004
# Posted on: 25-Aug-2009 15:11:50   

I have an primary key Id (int) field which I have identity disabled. We have removed the identity setting to make it easier to perform data synchronization scripts between our development and production servers (we don't have permissions to perform identity inserts on the production server).

When we insert new records via code, we would like to do something like the following

lock table
declare newId as int
select newId = max(Id) + 1 from table
insert into table values (newId, ...)
release lock

Is something like this possible or is there some built in feature to llblgen which will have llblgen handle the identity part?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 25-Aug-2009 20:45:38   

LLBLgen will not natively handle the identity for you if you have disabled it in the database.

You could run a transaction to select the next number from your table, create a new entity, set the id and the other fields, and then save - creating the transaction is effectivley the same as locking the table.

Another approach is to have a single "NextId" table for all the entities - you could then grab batches of numbers from this to use as set of ids.

Matt