.net - How can I insert a record with a specific identity using Linq with IDENTITY_INSERT set to ON -
i'm trying synchronize table between 2 databases using linq. want primary keys (identities) in both tables same. haven't been able accomplish using linq.
after scouring google, closest can this:
using dbcontext new dbcontext() 'somewhere read line below ensures queries run in same session dbcontext.connection.open() dim copyofshoe new shoe() copyofshoe.id = originalshoe.id copyofshoe.color = originalshoe.color dbcontext.executecommand("set identity_insert shoes on") dbcontext.shoes.insertonsubmit(copyofshoe) dbcontext.submitchanges() dbcontext.executecommand("set identity_insert shoes off") end using
but throws exception:
explicit value must specified identity column in table 'shoes' either when identity_insert set on or when replication user inserting not replication identity column.
i know can around using executecommand insert new record existing identity, want know if possible using linq.
Comments
Post a Comment