SCOPE_IDENTITY() to @@IDENTITY.

Posts   
 
    
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 11-Sep-2012 20:23:40   

In our entities, we have the sequence for the ID field (primary key) in SQL Server set up as @@IDENTITY. Every time when we make some changes to out LLBLGEN proj file, it automatically changes the sequence field mapping to SCOPE_IDENTITY().

So we have to remember everytime we make change to out project file, we have to manually change the sequence from SCOPE_IDENTITY() to @@IDENTITY. Is it a bug or are we missing anything here?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Sep-2012 23:18:22   

Reproduced.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 12-Sep-2012 13:02:25   

We'll look into it.

Btw, you should never use @@IDENTITY as sequence value, unless you have triggers on the tables which insert rows in identity sequenced tables as well. If you don't use these kind of triggers on the tables you should pick the default: scope_identity.

Why do you use @@IDENTITY?

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 13-Sep-2012 12:58:46   

Fixed in next build.

I'd still like to see the answer on my question why you'd need @@IDENTITY at all...

Frans Bouma | Lead developer LLBLGen Pro
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 13-Sep-2012 23:05:59   

because we have instead of insert trigger on table.

Check out this for more info...

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=20431

Reply from one of your guys:

Are you setting the [urldescription="SQL Compatibility level"]on you *.config?

My guess is that you have an InsteadOfInsert trigger on the EMP_SERVICE table. If that is the case, then SCOPE_IDENTITY won't work, you should use @@IDENTITY instead. So try the following: - Open your LLBLGen project and go to edit the EmpService entity. - Go to Field Mappings sub-tab. - Select the primary key field. There change it's sequence from SCOPE_IDENTITY to @@IDENTITY. - Regenerate the code and try again.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Sep-2012 10:45:37   

That's correct as said earlier, Triggers are the only reason to use @@Identity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 14-Sep-2012 10:45:55   

Ok, good point simple_smile I asked because I wanted to know whether we missed a use case.

The fix is now available btw.

Frans Bouma | Lead developer LLBLGen Pro