我试图关闭身份以插入我自己的值,我遵循的步骤
StoredGeneratedPattern值更改None为标识列 StoredGeneratedPattern值更改为NoneEDMX文件尝试使用以下代码
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();
}
Run Code Online (Sandbox Code Playgroud)
但我仍然收到错误
当IDENTITY_INSERT设置为OFF时,无法在表中插入标识列的显式值
我错过了什么吗?还有其他选择吗?
c# identity entity-framework entity-framework-4 entity-framework-4.1