Entity Framework Id auto incrementing

前端 未结 1 794
[愿得一人]
[愿得一人] 2021-01-20 13:56

Have a problem with incrementing. I created a new object and tried set it into my DB I received an error of data violation. The index in table wasn\'t increased (Id=0). Id

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-20 14:25

    Entity Framework does not automatically increment IDs. That's the database's job. Set the ID column on the database table as an IDENTITY column so that it will auto-increment. Then you should find that after you SaveChanges() the phone's ID property will have been set to the value the database chose for it.

    0 讨论(0)
提交回复
热议问题