How to fix the System.InvalidOperationException: The property 'PropertyID' is part of the object's key information and cannot be modified problem - 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 - 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.

 

Written By Steve French

 

Leave a Reply

Your email address will not be published. Required fields are marked *






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