I am trying to switch the identity off to insert my own value, steps I followed
- changed the property
StoredGeneratedPattern
value toNone
for the identity column - changed the property
StoredGeneratedPattern
value toNone
in EDMX file by opening in xml format
Tried using the below code
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
int k = Context.ExecuteStoreCommand("SET IDENTITY_INSERT dbo.client ON");
Context.ClientInfoes.Add(testclient);
result = Context.SaveChanges();
int j = Context.ExecuteStoreCommand("SET IDENTITY_INSERT dbo.client OFF");
scope.Complete();
}
but I am still receiving the error
Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF
Am I missing something? Are there any other options?