November 2015 - Digital Tool Factory blog November 2015 - Digital Tool Factory blog

The Digital Tool Factory Blog

How to fix the System.InvalidOperationException: The property ‘PropertyID’ is part of the object’s key information and cannot be modified problem

Often times when you are using Entity Framework and trying to update objects using the handy

db.Entry(useableProperty).CurrentValues.SetValues(property);

Method you will encounter the error

InvalidOperationException: The property ‘PropertyID’ is part of the object’s key information and cannot be modified problem

After lots of thought I came across the remarkably simple answer, to wit – the PropertyID field is not being EXPLICITLY included in the object you are passing back to the controller.  Just put that in a “HiddenFor and you’re all set.


02
Nov 15


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.