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]