此代码假设只更新表中的一个值,并保持所有其他值不变。
我怎么能找不到原因,db.SaveChanges不保存它。在调试器中我可以看到值已经改变,
这是我的代码
if (model.rev.GBU == "Good")
{
//This section will do:---- 1> get subjectId -- 2> Update only in the subjectid good rank
//Update this subjectid (int)good +1 data
model.sub.SubjectId = R_getvelue.SubjectId;
//get the relevant value from the Db
var Good = R_getvelue.Good;
int iGoodRating = Convert.ToInt32(Good);
//Add 1 (one )to the value in the Db
iGoodRating++;
model.sub.Good = iGoodRating;
//Keep All the existing data in the other fields
UpdateModel(model.sub);
// db.Entry(model.sub).State = EntityState.Modified; >removing all values biside "Good
}
await db.SaveChangesAsync();
return RedirectToAction("index");
}
ViewBag.OccupationId = new SelectList(db.occupation, "OccupationId", "OccupationDecription", model.Occupation);
return View(model);
}