c# - Entity Framework IDENTITY_INSERT ON doesn't work -
i have code supposed insert record identity insert on
using (mct_db_archiveentities ent = new mct_db_archiveentities()) { ent.executestorecommand("set identity_insert [clicks] on"); ent.clicks.attach(ck); ent.clicks.context.objectstatemanager.changeobjectstate(ck, system.data.entitystate.added); ent.savechanges(); }
i error.
cannot insert explicit value identity column in table 'clicks' when identity_insert set off.
it not supposed work. works if identity insert turned on on same connection real insert. in case 2 different connections can used. make work have maintain own db connection , pass objectcontext's constructor.