InvalidOperationException when calling SaveChanges in .NET Entity framework

后端 未结 8 1235
小蘑菇
小蘑菇 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:14

    This exception seems to tell you that you have equal values in severals rows in the Id column, which is supposed to only have unique values, because it's a key column. Entity Framework can handle such columns in two ways: either you (the Client) generates unique values, or the Server generates unique values. In your case it seems logical to allow the Server to generate autoincremented keys.

    Do you have the StoreGeneratedPattern key set for the Id column in your SSDL file?

    Here is an example from this blogpost:

    
        
        
    
    

提交回复
热议问题