I'm using a method that creates new Entries in a table. The method looks like this:
public void CreateProcessingTime(Guid userId, int activityId, int min, int max, int avg)
{
var t = new T_USER_ACTIVITY_PROCESSING_TIME
{
UAP_USR_ID = userId,
UAP_ACT_ID = activityId,
UAP_P_TIME_MIN = min,
UAP_P_TIME_MAX = max,
UAP_P_TIME_AVG = avg
};
_dbEntities.T_USER_ACTIVITY_PROCESSING_TIME.Add(t);
_dbEntities.SaveChanges();
}
Upon the SaveChanges();
it throws an error:
SqlException: Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF.
The SQL I used to generate the table was:
-- Creating table 'T_USER_ACTIVITY_PROCESSING_TIME'
CREATE TABLE [dbo].[T_USER_ACTIVITY_PROCESSING_TIME] (
[UAP_ID] int IDENTITY (1,1) NOT NULL,
[UAP_USR_ID] uniqueidentifier NOT NULL,
[UAP_ACT_ID] int NOT NULL,
[UAP_P_TIME_MIN] int NOT NULL,
[UAP_P_TIME_AVG] int NOT NULL,
[UAP_P_TIME_MAX] int NOT NULL
);
GO
SET IDENTITY_INSERT [T_USER_ACTIVITY_PROCESSING_TIME] ON
-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------
-- Creating primary key on [UAP_ID] in table 'T_USER_ACTIVITY_PROCESSING_TIME'
ALTER TABLE [dbo].[T_USER_ACTIVITY_PROCESSING_TIME]
ADD CONSTRAINT [PK_T_USER_ACTIVITY_PROCESSING_TIME]
PRIMARY KEY CLUSTERED ([UAP_ID] ASC);
GO
I tried setting SET IDENTITY_INSERT T_USER_ACTIVITY_PROCESSING_TIME ON
on the SQL Server Manager, but it did not resolve the issue. My next guess would be that I had to change something on the .edmx but I can't seem to find the correct place.
What else can I do to resolve the error?