entity framework - Cannot insert explicit value for identity column in table 'LeistungGruppe' when IDENTITY_INSERT is set to OFF -
i'm trying add entityobject database calling addtoleistunggruppe.
leistunggruppe in case table primary_key leistunggruppe_id identity true , identity increment 1 , seed 1.
i search lot issue , alot of people got same error. told set storegeneratedpattern identity , solve problem.
i tried out , still got same issue. i'm new entity framework , have no idea how solve problem.
somehow think model isn't updated because if switch around these settings i'm getting same error on , on again.
every appreciated.
you trying save object database explicit id set while database expecting generate value itself. leistunggruppe_id property in object set other 0 , not identified ef framework identity field. if want id generated database post suggests, corresponding property in object should decorated [key] attribute.
if using fluent api should have in dbcontext:
protected override void onmodelcreating(system.data.entity.modelconfiguration.modelbuilder modelbuilder) { modelbuilder.entity<leistunggruppe>().property(x => x.leistunggruppe_id).storegeneratedpattern = storegeneratedpattern.identity; base.onmodelcreating(modelbuilder); }
Comments
Post a Comment