Adapter tries identity insert with Id=0 even though IsNew=true

Posts   
 
    
AndiDog
User
Posts: 6
Joined: 28-Sep-2011
# Posted on: 18-Oct-2011 11:01:22   

The title says it all. I have a m:n relationship table UserRoles with the identity Id and the two foreign keys UserUserId and RoleRoleId. Then when I try to persist such a UserRolesEntity instance, I get the error

Cannot insert explicit value for identity column in table 'UserRoles' when IDENTITY_INSERT is set to OFF.

because the adapter tries to insert a zero there as Id instead of not filling the value:

INSERT INTO [eTrash].[dbo].[UserRoles] ([Id], [UserUserId], [RoleRoleId]) VALUES (0,4,3)

With all other entities, inserts work without problems. What could I possibly be doing wrong?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Oct-2011 11:42:50   

Please check the field mapping in the LBLGen Pro Designer. It should have Scope_Identity() under the Sequence column.

AndiDog
User
Posts: 6
Joined: 28-Sep-2011
# Posted on: 18-Oct-2011 15:04:49   

I resolved this problem. Actually the Id field was set to SCOPE_IDENTITY already and committed in the database, but I had forgotten to re-generate the adapter code. Thanks for your help!