linq to sql - "Cannot insert explicit value for identity column..." even though I'm not -


i have function:

private static void saveresource(strategicplanningdbdatacontext ctx, resourcemodel resource, int impliedid)     {         var existing = ctx.resources.firstordefault(r => r.id == resource.id) ??                        new resource();          existing.impliedid = impliedid;         existing.hasaccepted = resource.hasaccepted;         existing.isprimary = existing.isprimary;         existing.userid = resource.userid;          if (existing.id == default(int))         {             ctx.resources.insertonsubmit(existing);             ctx.submitchanges();             resource.id = existing.id;         }     } 

i'm getting cannot insert explicit value identity column in table 'resource' when identity_insert set off. message when hit ctx.submitchanges() new resource. resource.id identity (obviously). it's 0 when come function (because created it, , ints have have default value.

i've tried deleting table dbml , re-adding several times, keep getting error. i've checked designer, , designer has [global::system.data.linq.mapping.columnattribute(storage="_id", autosync=autosync.oninsert, dbtype="int not null identity", isprimarykey=true, isdbgenerated=true)] above id property.

any ideas?

well, closed , restarted visual studio , got better. (as aside, compiling fine if removed tables .dbml, which, uh, didn't make sense).


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -