IDENTITY_INSERT Error on table in which I am not even trying to insert?
I am getting this Error:
SqlException: Cannot insert explicit value for identity column in table 'Unterwerke' when IDENTITY_INSERT is set to OFF.
..when I am Trying to insert something into the table "Clients". Every Client has 1 Unterwerk but i am never inserting an Unterwerk in my code.
This is how I insert the client:
3 Replies
You'll need to provide more context and code. Show Client and Unterwerke declarations and any EF Configurations
Every Client has 1 UnterwerkThat implies that inserting a Client also causes an Unterwerk to be inserted, unless some Clients do not actually have Unterwerks. But this problem is deeper than inserting an Unterwerk unexpectedly. Presumably you would want to eventually insert one, and at that point you will run into this problem anyway.
I've fixed it. @Grault you are correct, it wanted to insert a new Unterwerk, i just added UnterwerkID to the Model and filled that instead of the Unterwerk obejct