Identifying generated sequence number

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 05-Jul-2012 17:17:19   

LLBLGen 3.5 SQL Server 2005 .NET Framework 4.0 LLBLGen runtime frame work C# Windows Application

Dear Support team,

In Self Servicing, Is there a way to find out the sequence number that will be generated in SQL prior to commit ?

I mean let us say I have a table called DEMO with columns

DEMOID - auto generated sequence Description - Varchar

Prior to executing commit, is there a way for me to know what is the sequence number that is going to be inserted on commit?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Jul-2012 18:43:51   

You can manually query the database for the last inserted sequence (in case it was an identity field), so you can predict the next one to a great extent. Provided you guarantee that no one else is inserting at the same time. (using a queue or a critical section for example).

But why do you need this anyway?

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 07-Jul-2012 06:10:49   

shekar wrote:

LLBLGen 3.5 SQL Server 2005 .NET Framework 4.0 LLBLGen runtime frame work C# Windows Application

Dear Support team,

In Self Servicing, Is there a way to find out the sequence number that will be generated in SQL prior to commit ?

I mean let us say I have a table called DEMO with columns

DEMOID - auto generated sequence Description - Varchar

Prior to executing commit, is there a way for me to know what is the sequence number that is going to be inserted on commit?

I need to get the seq value prior commit, add prefix to it and insert in another column for some other business logic purpose. Going by your suggestion, I cannot guarantee that no one else is inserting at same time.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jul-2012 01:26:34   

What if you insert and use the identity field to add your prefix and update the entity?

David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 09-Jul-2012 07:21:22   

daelmo wrote:

What if you insert and use the identity field to add your prefix and update the entity?

You mean dont auto generate PK just generate and insert?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Jul-2012 19:37:07   

David meant to Update the Entity after Insertion. You Insert and get back the value of the Inserted (AuoGenerated PK), then you Update the entity as you wish. (2 database transactions).

You would need 2 transactions in all ways. so the above might be the best approach. Unless you want to take this at the DB level, using a trigger.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 10-Jul-2012 06:13:21   

Walaa wrote:

David meant to Update the Entity after Insertion. You Insert and get back the value of the Inserted (AuoGenerated PK), then you Update the entity as you wish. (2 database transactions).

You would need 2 transactions in all ways. so the above might be the best approach. Unless you want to take this at the DB level, using a trigger.

Ok Thank you