Unit testing with identity columns
问题 I am using IDENTITY columns in my SQL Server tables. I have a unit test where I delete a data record with a certain id. When I insert the testdata I get this exception: Cannot insert explicit value for identity column in table 'MyTablename' when IDENTITY_INSERT is set to OFF Then I do a quick test in my management studio: SET IDENTITY_INSERT MyTablename ON It says Command(s) completed successfully. I rerun the unit test but still get the same error. How do I go about that in general? I want