Primary key not part of insert statement

Posts   
 
    
rboarman
User
Posts: 83
Joined: 01-Feb-2005
# Posted on: 03-Aug-2010 01:43:38   

Hello,

I am using 3.0.10.0611 in adapter mode.

My issue is that I am trying to set a primary key value on a new entity. When I call adapter.SaveEntity() I get an “primary key cannot be null” error. The sql that is generated is not including the primary key field at all. The other fields are there in the sql just not the primary key.

The primary key field, RowId, is not an identity field but it used to be. The project has been refreshed and regenerated since I removed the identity specification.

I am not sure where to go with this to get it running.

Thank you,

Rick

Code:

var userEntity = new UserEntity();

// Copy in the data from the DTO object         
Mapper.Map<UserDTO, UserEntity>(userDTO, userEntity);
                userEntity.Fields[(int)UserFieldIndex.RowId].ForcedCurrentValueWrite(userDTO.RowId);
userEntity.Fields[(int)UserFieldIndex.RowId].IsChanged = true;
                
dbAdapter.SaveEntity(userEntity, true);

Generated SQL Code:

declare @p6 int
set @p6=NULL
exec sp_executesql N'INSERT INTO [MyDB].[dbo].[Users] ([AspnetUserGuid], [CreatedDate], [M6Bucks], [UpdatedDate]) VALUES (@p1, @p2, @p3, @p5) ;SELECT @p4=SCOPE_IDENTITY()',N'@p1 uniqueidentifier,@p2 datetime,@p3 int,@p4 int output,@p5 datetime',@p1='6513D3E8-EDB4-4652-9B0F-DD939958A438',@p2='2010-08-02 22:30:35.0530000',@p3=0,@p4=@p6 output,@p5='2010-08-02 22:30:35.0530000'
select @p6

Schema:

CREATE TABLE [dbo].[Users](
    [RowId] [int] NOT NULL,
    [AspnetUserGuid] [uniqueidentifier] NOT NULL,
    [M6Bucks] [int] NOT NULL,
    [CreatedDate] [datetime] NOT NULL,
    [UpdatedDate] [datetime] NOT NULL,
    [RowTimestamp] [timestamp] NOT NULL,
 CONSTRAINT [PK__Users__FFEE74316D6D25A7] PRIMARY KEY CLUSTERED 
(
    [RowId] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Aug-2010 06:32:36   

Does the field has a sequence assigned? Could you please attach your llblgen project?

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 03-Aug-2010 12:18:14   

Looking at the generated query, there's still a sequence mapped to the field. Could you check the sequence column in the field mappings?

Also, please download a newer build from our website and use that for refreshing. We had some bugs in the refresher.

Frans Bouma | Lead developer LLBLGen Pro
rboarman
User
Posts: 83
Joined: 01-Feb-2005
# Posted on: 03-Aug-2010 17:48:54   

It turns out that what I needed to do was to remove the entity from the designer and re-add it. The designer did not pick up on the fact that I had removed the identity specification even though I refreshed.

Rick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 03-Aug-2010 18:59:56   

rboarman wrote:

It turns out that what I needed to do was to remove the entity from the designer and re-add it. The designer did not pick up on the fact that I had removed the identity specification even though I refreshed.

Rick

but... did you use the latest build? If it still doesn't pick this up we have to look into this.

Frans Bouma | Lead developer LLBLGen Pro