Identity problem

Posts   
 
    
dkuc
User
Posts: 3
Joined: 12-Jul-2005
# Posted on: 12-Jul-2005 20:20:44   

I have a 2 SQL Server 2000 tables, each with a primary key marked as an identity field. I am attempting to simply insert into each table and retrieve back the primary key immediately following the Save() call. I am able to do this successfully with one table, but not in the other. The record in the second table does get created with a new primary key, but it gets returned in code as a 0. I have refreshed the tables, regen'ed the code, and rebuilt/reregistered but have had no luck. Does anyone have any suggestions as to what may be wrong?

Thank you in advance.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 20:50:53   

Could you please check if the second entity in the designer has 'IsIdentity' set to true for the PK field?

Frans Bouma | Lead developer LLBLGen Pro
dkuc
User
Posts: 3
Joined: 12-Jul-2005
# Posted on: 12-Jul-2005 21:31:55   

Otis wrote:

Could you please check if the second entity in the designer has 'IsIdentity' set to true for the PK field?

Yes, the IsIdentity is set to True.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 22:27:09   

Ok, so in the generated code it also should be mentioned that the field is an identity field.

Please check the FactoryClasses\EntityFieldFactory.cs/vb file and browse down to the create method for the entity in question. Then check the field in question and it should have at the end of the call "SCOPE_IDENTITY()" instead of "". If not, it's not generated as being an identity field. This can for example be caused by the fact that the file was readonly when you generated the code (not checked out of VSS for example).

If it does, please check that the application you're using the code with has the latest compiled assembly of the generated code.

Could you also paste here the code you use to save the entities? Thanks.

Frans Bouma | Lead developer LLBLGen Pro
dkuc
User
Posts: 3
Joined: 12-Jul-2005
# Posted on: 12-Jul-2005 22:35:53   

Otis wrote:

Ok, so in the generated code it also should be mentioned that the field is an identity field.

Please check the FactoryClasses\EntityFieldFactory.cs/vb file and browse down to the create method for the entity in question. Then check the field in question and it should have at the end of the call "SCOPE_IDENTITY()" instead of "". If not, it's not generated as being an identity field. This can for example be caused by the fact that the file was readonly when you generated the code (not checked out of VSS for example).

If it does, please check that the application you're using the code with has the latest compiled assembly of the generated code.

Could you also paste here the code you use to save the entities? Thanks.

Thank you for your help, Otis. I just determined that my code was accessing an older assembly referenced in the GAC. Everything works fine now.