EF code first: Cannot insert explicit value for identity column in table '' when IDENTITY_INSERT is set to OFF

前端 未结 2 1653
旧巷少年郎
旧巷少年郎 2020-12-11 23:10

I have issue with EF code first

when I am trying to insert new record into table I recieve message.

Cannot insert explicit value for identity column          


        
2条回答
  •  猫巷女王i
    2020-12-11 23:29

    You don't need to change mapping code, instead you should change this line:

    lngRequestLineID = 1001233
    

    to this:

    lngRequestLineID = 0
    

    In my expirence decorating de Id entity's property with [KeyAttribute] is enought.

提交回复
热议问题