InvalidOperationException when calling SaveChanges in .NET Entity framework

后端 未结 8 1260
小蘑菇
小蘑菇 2020-12-03 17:22

I\'m trying to learn how to use the Entity framework but I\'ve hit an issue I can\'t solve. What I\'m doing is that I\'m walking through a list of Movies that I have and ins

8条回答
  •  鱼传尺愫
    2020-12-03 18:04

    I found the solution to this.

    What happened was that when I created my table I forgot to add the primary key and set (Is Identity) property to yes. I then created my Entity model and got this error.

    I went back and fixed my database table but I still hade the weird Exception. What solved the problem in the end was to remove the entity and re-create it after the table was fixed.

    No more exceptions :)

提交回复
热议问题