Reputation: 27996
I am trying to update my entity using Entity Framework 4.1 code First approach like this(In my Repository Class):
internal void SaveAccount(Account account) {
context.Entry(account).State = EntityState.Modified;
context.SaveChanges();
}
but I am getting an error which is:
Cannot update identity column 'Unique ID'.
I am not updating Unique ID Column. How can I avoid this error ?
Upvotes: 4
Views: 3781
Reputation: 91
If the property is the primary key, the following attribute should be added instead:
[Key]
Upvotes: 1
Reputation: 27996
I added this attribute to my Model property and error gone:
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
Upvotes: 6