我正在尝试更新表中的一行。我找到了一种让它工作的方法,但我想知道是否有更简单或更好的方法。请帮助我解决您可能有的任何想法。谢谢
这是代码……</p>
var courseRubics = from r in db.Rubrics where r.DepartmentID == 2 select r;
var selectedRubrics = courseRubics.Select(r => r.RubricID);
List<int> rubricsList = selectedRubrics.ToList();
foreach (var rub in courseRubics.ToList())
{
if (!String.IsNullOrEmpty(formCollection["item.Weight"]))
{
Rubric aRubic1 = db.Rubrics.Find(1);
Rubric updateRubic1 = (Rubric)aRubic1;
int rubric1 = Convert.ToInt32(totlrubric[0]);
updateRubic1.Weight = rubric1;
Rubric aRubic2 = db.Rubrics.Find(2);
Rubric updateRubic2 = (Rubric)aRubic2;
int rubric2 = Convert.ToInt32(totlrubric[1]);
updateRubic2.Weight = rubric2;
Rubric aRubic3 = db.Rubrics.Find(4);
Rubric updateRubic3 = (Rubric)aRubic3;
int rubric3 = Convert.ToInt32(totlrubric[2]);
updateRubic3.Weight = rubric3;
}
db.SaveChanges();
}