This is a general concept question dealing with the Edit life-cycle in MVC.
As I understand it, the Edit GET action pulls the requested instance from the db context and ends by passing that instance to the Edit View (where the instance is referred to as the view model).
The Edit View uses stuff like this:
@Html.HiddenFor(model => model.SomethingIDoNOTWantEdited)
<div class="form-group">
@Html.LabelFor(model => model.SomethingIDoWantEdited, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.SomethingIDoWantEdited, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SomethingIDoWantEdited, "", new { @class = "text-danger" })
</div>
</div>
to display some or all of the properties of the view model so that the user can change the values if needed.
When the user clicks the submit button the Edit POST Action is called, and when used with something like this
[HttpPost]
public ActionResult Edit([Bind(Include = "Id, SomethingIDoWantEdited, SomethingIDoNOTWantEdited")] MyClass viewModel)
Makes a bright shiny new object of type MyClass called viewModel.
Now, I know I could do a query on the context and get the current object in the db that has that Id, and then copy all the fields from viewModel to the existing one before marking the original as modified and then calling SaveChanges(). That's not too bad when there are only a few properties to copy, but when there are lots of them it becomes cumbersome.
Is there a better way to get the items the user changed written back to the database?