This is a migrated thread and some comments may be shown as answers.

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

1 Answer 608 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 16 Apr 2015, 05:20 PM

I've seen this exception referenced in a few threads with some users seemingly never getting it resolved. This particular solution is situation-specific but I wanted to post it here for anyone who may be experiencing the issue for the same reasons I was.



ISSUE: 
---------------------------
Cannot insert explicit value for identity column in table 'YourTableNameHere' when IDENTITY_INSERT is set to OFF.



SITUATION: 
---------------------------
In my particular case I was getting this same error because I had a field other than than the primary key set as the Identity Field!


Pertinent fields from Table:

Fieldname: ProjectId (Primary Key)
Type: UniqueIdentifier
RowGuid: True

Fieldname: ClusterIndex
Type: Int
Identity Specification: Yes


It was all but impossible to tell from the huge exception but it was actually the attempt to write to the ClusterIndex field that was throwing the exception!



SOLUTION:
---------------------------

1) Open the rlinq file and in the designer click the offending field (ClusterIndex in my case). 

2) In the Visual Studio Properties Editor set "Kind" to: "PersistentReadOnly".

3) Save

That's it! Now this field will NOT attempt to be written to when adding/updating records - and thus no more exception!


Alternatively you could probably just remove the offending field from the entity model completely if you have no need for it in your code, etc.



Hope this helps someone else!
 

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 21 Apr 2015, 05:23 PM
Hello Michael,

The solution you describe is the recommended one when the configuration matches the one on your side.

Thank you for taking the time to investigate the issue and to share the outcome.


Regards,
Doroteya
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Michael
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or