MVC4 Entity Framework one paticular column not updating
I am having an infuriating issue where one paticular column in my entity
will not save/update. I have tried numerous methods of updating the row
such as manally assigning each property I want to update, to where I am
now (see code block below). 2 columns update and save as expected
(absent_type_id, and point_value) however no matter what I do the
"description" column just will not save.
I have checked the debugger to see what the value is before the
db.SaveChanges(); and confirmed it is set to the new value; however,
selecting the row after the save (and checking the database) shows that
the others values are updated, but the description reverts back to what it
was...why could this be?
[HttpPost]
public JsonResult UpdateOccurrence(int occ_id,
string absent_type,
string description,
int point_value)
{
try
{
// Get id for the absent type
int absent_type_id = db.AT_absent_types.Single(a =>
a.absent_type == absent_type).absent_type_id;
var occurrenceToUpdate = new AT_occurrences
{
occ_id = occ_id,
absent_type_id = absent_type_id,
description = description,
point_value = point_value
};
db.AT_occurrences.Attach(occurrenceToUpdate);
db.SaveChanges();
//return call omitted
}
catch (Exception ex)
{
return Json(new {Result = "ERROR", Message = ex.Message});
}
}
As I mentioned - posting the point_value and absent_type save and update
the entity perfectly, the description just will not save! i have no idea
why. Any help or insight would be very much appreciated - this is driving
me crazy! Cheers!
No comments:
Post a Comment