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

1 Answer 9203 Views
General Discussions Grid
Andi
Top achievements
Rank 1
Iron
Iron
Andi asked on 03 Oct 2022, 07:04 PM

Hello Telerik Developers. I am new to Progress Telerik but I am catching up faster than I ever thought.

I was looking to add a new item into my database. While adding I get the error above.

The Primarykey in this case is set to autogenerate in the database and I have it specified in its Context Class:

entity.Property(e => e.Id).ValueGeneratedOnAdd().HasColumnName("id");

Is there any option to adding without setting the  IDENTITY_INSERT TABLE ON? 

I am looking to have the Id incremented on Add without having to enter it on my own. I was looking at a solution here, but that is not what I am looking for.

 

Any help is appreciated.

 

Thank you.

 

 

1 Answer, 1 is accepted

Sort by
0
Stoyan
Telerik team
answered on 06 Oct 2022, 12:28 PM | edited on 06 Oct 2022, 04:35 PM

Hello Andi,

As far as I understand the question it seems more related to databases rather than the Grid.

That being said for SQL you can use SET IDENTITY_INSERT TABLE ON add the needed column and then use SET IDENTITY_INSERT TABLE OFF as suggested in the How to turn IDENTITY_INSERT on and off stackoverflow thread

or

for Entity Framework refer to the related article How to turn on identity-insert in .net core.

I hope the information above is useful.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Andi
Top achievements
Rank 1
Iron
Iron
commented on 06 Oct 2022, 03:11 PM

Hello Stoyan,

Yes I realized this morning that it was not the grid. In fact I can add or delete but every time I update I get an error from the database. Please disregard this question and another question in the forum as I am investigating the issue.

Thank you for your support. 

Andi.

Tags
General Discussions Grid
Asked by
Andi
Top achievements
Rank 1
Iron
Iron
Answers by
Stoyan
Telerik team
Share this question
or