本文介绍了如何在asp.net-mvc3中更新两个或多个实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新两个这样的实体:

Hi, I’m trying to update two entities like this:

for (int i = 0; i < numberOfRows i++)
 {

     var enrollment = db.Enrollments.SingleOrDefault(x => x.EnrollmentID == i+1);
     var student = db.Students.SingleOrDefault(x => x.StudentID == i+1);

     student.FirstMidName = AllFstMNames[i];
     enrollment.Grade = Convert.ToInt32(AllGrades[i]);

     student.EnrollmentDate = Convert.ToDateTime(AllEnrollmentDates[i]);

    if (!string.IsNullOrEmpty(frmcol["item.Grade"]))
                    {
                        enrollment.Grade = Convert.ToInt32(AllGrades[i]);


                    }
     enrollment.StudentID = Convert.ToInt32(AllStudentIds[i]);
     enrollment.attendanceCode = Convert.ToInt32(AllAttendanceCodes[i]);
//more code that assign form values to entity properties.

     db.SaveChanges();
 }


我想要的是仅将更改应用于视图中更改的字段.我该怎么办?

感谢您的帮助!


What I want is to have changes applied only to the fields that I change in the view. How can I accomplish this?

Thanks for any help!

推荐答案


这篇关于如何在asp.net-mvc3中更新两个或多个实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 06:01