I'm relatively new to this but I'm still a little embarrassed as this really should be simple...
All I'm trying to do is update an existing row in a database table. I'm using EF (5 I believe) code first.
For MVC 3 I used this approach (which worked):
ReportCommon reportcommon = db.ReportCommon.Single(r => r.ReportCommonId == id);
reportcommon.IP = StaticUtilities.GetIPAddress();
db.ObjectStateManager.ChangeObjectState(reportcommon, EntityState.Modified);
db.SaveChanges();
I've tried a few examples that I've found and although they don't error the database doesn't get updated...
[HttpPost]
public ActionResult Edit(CitizenEntryViewModel citizenDetails)
{
ActiveCitizen activeCitizen = db.ActiveCitizen.SingleOrDefault(m => m.ID == citizenDetails.ActiveCitizen.ID);
if (activeCitizen != null)
{
citizenDetails.ActiveCitizen.CitizenUpdatedRecordOn = DateTime.Now;
// Fields we don't edit but still need to pass back
citizenDetails.ActiveCitizen.PublicID = activeCitizen.PublicID;
citizenDetails.ActiveCitizen.IsKIN = activeCitizen.IsKIN;
activeCitizen = citizenDetails.ActiveCitizen;
db.SaveChanges();
}