-1

Say I have a device entity that has many fields, and some navigational properties. When the user clicks edit for a particular device, we only want them to be able to edit some of those properties. Which implementation is recommended? (Is there a standard way of doing this)

  1. Have hidden fields for all the properties of the device in the view, and even large hidden lists for the many relational navigation properties it may have. When the edit is posted, save all the changes to the entity using SaveChanges() - so that means let EF figure out what changed. (I'm not even sure MVC will be able to model bind the navigational prop's without some customization.)

  2. Have a separate model, like EditDeviceModel that only has the properties that you would like to edit, and write a method for saving this model specifically to update the entity.

  3. Option I didn't think of???

Dave
  • 1,645
  • 2
  • 23
  • 39
  • Use view models representing only what you want to edit [What is a viewmodel in mvc](http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc) –  Dec 16 '14 at 20:28

1 Answers1

0

You are on the right track with EditDeviceModel. The standard approach would be to create a View Model to bind to the view. You would then update the entity with the fields that have changed and call SaveChanges.

Scott Murphy
  • 448
  • 2
  • 12