0

我使用以下代码

Tel_CallHistory CallHistory = new Tel_CallHistory();


                     CallHistory.MobileNo = MobileNo;
                     CallHistory.CRId = CallResponse;
                     CallHistory.CallRemark = CallRemark;
                     CallHistory.UserId = UserId;
                     CallHistory.CallDate = DateTime.Now;
                     CallHistory.CallTime = DateTime.Now.TimeOfDay;

                     CallHistory.MeetingPoint = meetingpoint;
                     if (CallResponse == 1)
                     {
                         CallHistory.NCallDateOn = null;
                         CallHistory.NCallTimeAt = null;
                         CallHistory.MeetingDate = Convert.ToDateTime( meetingdate);

                         CallHistory.MeetingTime =  DateTime.Parse(meetingtime).TimeOfDay;
                     }
                     else
                     {

                         CallHistory.NCallDateOn =  Convert.ToDateTime(NCallDateOn);

                         CallHistory.NCallTimeAt =  DateTime.Parse(NCallTimeAt).TimeOfDay;  

                         CallHistory.MeetingDate = null;
                         CallHistory.MeetingTime = null;
                     }


                     db.Tel_CallHistory.AddObject(CallHistory);


                     Tel_Mobile TelMobile = _teacher.getDB().Tel_Mobile.Single(a => a.MobileNo == MobileNo);
                     TelMobile.CallDate = CallHistory.NCallDateOn;
                     TelMobile.CallTime = CallHistory.NCallTimeAt;

                     TelMobile.LCallDateOn = CallHistory.CallDate;
                     TelMobile.LCallTimeAt = CallHistory.CallTime;
                     TelMobile.LCRId = CallHistory.CRId;
                     TelMobile.LCallRemark = CallHistory.CallRemark;
                     TelMobile.LMeetingPoint = CallHistory.MeetingPoint;
                     TelMobile.LMeetingDate = CallHistory.MeetingDate;
                     TelMobile.LMeetingTime = CallHistory.MeetingTime;

                      db.Tel_Mobile.ApplyOriginalValues(TelMobile);


                     db.SaveChanges();



                     db.AcceptAllChanges();

但是当db.Tel_Mobile.ApplyOriginalValues(TelMobile)执行时,显示错误

在 ObjectStateManager 中找不到具有与所提供对象的键匹配的键的对象。验证必须应用更改的对象未处于已添加状态,并且其键值与所提供对象的键值匹配。

4

1 回答 1

0

你可能想附上它。

db.Tel_Mobile.Attach(TelMobile);
于 2012-09-14T12:27:17.113 回答