日期:2014-05-20  浏览次数:20753 次

EntitySet调用add方法去没有改变Untracked state
本帖最后由 XieeEvil 于 2012-04-08 17:00:39 编辑
EntitySet 调用add方法后没有将object state 从Untracked 修改为可被datacontext跟踪的状态,导致
EntitySet add一个新的Entity或修改里面的一个实体 调用submitchanges后发现数据库没有保存更改
下面试代码:

初始化:
           IEnumerable<T_XEStudent> students = context.GetTable<T_XEStudent>();
            string studentName = this.cmbStudentName.Text;
            CurrentSelectedStudent = students.SingleOrDefault(m => m.StudentName.Equals(studentName));
            currentPaper = CurrentSelectedStudent.T_XEPapers.SingleOrDefault();

        private void btnSavePingYue_Click(object sender, EventArgs e)
        {
            T_XEComment com=currentPaper.T_XEComments.SingleOrDefault(m => m.CommentTeacherName.Equals(teacher.TeacherName));
            //修改评语 数据库中友Comment记录 
            if (com!=null)
            {   
                com.ReceiveScoreSelectSubject = Convert.ToInt32(this.cmbReceiveScoreSelectSubject.Text);
                com.RecieveScoreComprehensiveSkill = Convert.ToInt32(this.cmbRecieveScoreComprehensiveSkill.Text);
                com.RecieveScoreReferenceDocument = Convert.ToInt32(this.cmbRecieveScoreReferenceDocument.Text);
                com.RecieveScoreWritingLevel = Convert.ToInt32(this.cmbRecieveScoreWritingLevel.Text);
                com.RecieveScoreStudingLevel = Convert.ToInt32(this.cmbRecieveScoreStudingLevel.Text);
                com.RecieveScoreFormat = Convert.ToInt32(this.cmbRecieveScoreFormat.Text);
                com.CommentContent = this.txtBoxComment.Text;
                if (teacherService.SavePingYue())           //修改记录后保存 调用public bool SaveChanges()方法
                {
                    MessageBox.Show("修改评阅内容成功");
                }
                else
                {