MVC SaveChanges没有保存,也没有返回错误

时间:2013-11-25 23:12:25

标签: asp.net-mvc linq entity-framework

我有以下代码似乎执行正常。它没有抛出任何错误,但实际上没有任何东西在db中保存..

//write record to callque so we dont have to wait for IVRDM to hit
               tblCallQue tblcallque = new tblCallQue();
               tblcallque.ProjectCode = SessionVars.Session_ProjectCode;
               tblcallque.PhoneNumber = SessionVars.Session_PriPhone;
               tblcallque.IVRStartDate = DateTime.Now.AddDays(-1);
               tblcallque.IVRStopDate = DateTime.Now.AddDays(1);
               tblcallque.CallerID = "7208577900";
               tblcallque.RepositoryID = tblcallrepository.RepositoryID;
               tblcallque.AnswerTimeout = 30;
               tblcallque.Active = true;
               tblcallque.Mon_StartTime = "0800";
               tblcallque.Mon_StopTime = "2000";
               tblcallque.Tue_StartTime = "0800";
               tblcallque.Tue_StopTime = "2000";
               tblcallque.Wed_StartTime = "0800";
               tblcallque.Wed_StopTime = "2000";
               tblcallque.Thu_StartTime = "0800";
               tblcallque.Thu_StopTime = "2000";
               tblcallque.Fri_StartTime = "0800";
               tblcallque.Fri_StopTime = "2000";
               tblcallque.Sat_StartTime = "0800";
               tblcallque.Sat_StopTime = "2000";
               tblcallque.Sun_StartTime = "0800";
               tblcallque.Sun_StopTime = "2000";
               tblcallque.TextMessage = tblcalltype.TextMessage;
               tblcallque.ManuallyTriggerCall = true;
               tblcallque.Debug = true;
               dbMaster.tblCallQues.AddObject(tblcallque);
               dbMaster.SaveChanges();

谢谢!

当我通过即时窗口查看tblcallque中的内容时,我得到了这个......这看起来对我有用,就像我说的那样,没有错误被抛出。

?tblcallque
{IVRDashboard.Models.tblCallQue}
    base {System.Data.Objects.DataClasses.EntityObject}: {IVRDashboard.Models.tblCallQue}
    _Active: true
    _AnswerTimeout: 30
    _CallerID: "7208577900"
    _Debug: true
    _Fri_StartTime: "0800"
    _Fri_StopTime: "2000"
    _ID: 0
    _IVRStartDate: {11/25/2013 9:14:55 AM}
    _IVRStopDate: {11/27/2013 9:14:55 AM}
    _ManuallyTriggerCall: true
    _Mon_StartTime: "0800"
    _Mon_StopTime: "2000"
    _PhoneNumber: "3036141227"
    _ProjectCode: "DEM"
    _RepositoryID: 1167
    _Sat_StartTime: "0800"
    _Sat_StopTime: "2000"
    _Sun_StartTime: "0800"
    _Sun_StopTime: "2000"
    _TextMessage: false
    _Thu_StartTime: "0800"
    _Thu_StopTime: "2000"
    _Tue_StartTime: "0800"
    _Tue_StopTime: "2000"
    _Wed_StartTime: "0800"
    _Wed_StopTime: "2000"
    Active: true
    AnswerTimeout: 30
    CallerID: "7208577900"
    Debug: true
    Fri_StartTime: "0800"
    Fri_StopTime: "2000"
    ID: 0
    IVRStartDate: {11/25/2013 9:14:55 AM}
    IVRStopDate: {11/27/2013 9:14:55 AM}
    ManuallyTriggerCall: true
    Mon_StartTime: "0800"
    Mon_StopTime: "2000"
    PhoneNumber: "3036141227"
    ProjectCode: "DEM"
    RepositoryID: 1167
    Sat_StartTime: "0800"
    Sat_StopTime: "2000"
    Sun_StartTime: "0800"
    Sun_StopTime: "2000"
    TextMessage: false
    Thu_StartTime: "0800"
    Thu_StopTime: "2000"
    Tue_StartTime: "0800"
    Tue_StopTime: "2000"
    Wed_StartTime: "0800"
    Wed_StopTime: "2000"

1 个答案:

答案 0 :(得分:0)

嗯,似乎我解决了 - 虽然我不确定为什么这会起作用。如果有人知道,请随时回复。

最初我有以下代码......

if (tblcallrepository != null)
           {
               //write record to callque so we dont have to wait for IVRDM to hit
               IVRMaster_VoxeoEntities dbMaster = new IVRMaster_VoxeoEntities(SessionVars.Session_IVRMasterConnectString);
               tblCallQue tblcallque = new tblCallQue();
               tblcallque.ProjectCode = SessionVars.Session_ProjectCode;
               tblcallque.PhoneNumber = SessionVars.Session_PriPhone;
               tblcallque.IVRStartDate = DateTime.Now.AddDays(-1);
               tblcallque.IVRStopDate = DateTime.Now.AddDays(1);
               tblcallque.CallerID = "7208577900";
               tblcallque.RepositoryID = tblcallrepository.RepositoryID;
               tblcallque.AnswerTimeout = 30;
               tblcallque.Active = true; 
               tblcallque.Mon_StartTime = "0800";
               tblcallque.Mon_StopTime = "2000";
               tblcallque.Tue_StartTime = "0800";
               tblcallque.Tue_StopTime = "2000";
               tblcallque.Wed_StartTime = "0800";
               tblcallque.Wed_StopTime = "2000";
               tblcallque.Thu_StartTime = "0800";
               tblcallque.Thu_StopTime = "2000";
               tblcallque.Fri_StartTime = "0800";
               tblcallque.Fri_StopTime = "2000";
               tblcallque.Sat_StartTime = "0800";
               tblcallque.Sat_StopTime = "2000";
               tblcallque.Sun_StartTime = "0800";
               tblcallque.Sun_StopTime = "2000";
               tblcallque.TextMessage = tblcalltype.TextMessage;
               tblcallque.ManuallyTriggerCall = true;
               tblcallque.Debug = false; 
               dbMaster.tblCallQues.AddObject(tblcallque);
               dbMaster.SaveChanges();
           }

我把它改成了这个,现在它可以工作......(只是把它移到了第一个IF语句之外)

if (tblcallrepository != null)
           {
               bContinue = true;
               //lookup calltpeid
                tblcalltype = db.tblCallTypes.SingleOrDefault(t => t.CallTypeID == tblcallrepository.CallTypeID);
               sResult = "Call has been triggered";
           }


           if (bContinue)
           {
               //now we trigger it here
               //tblcallrepository.ManuallyTriggerCall = true;
               //db.tblCallRepositories.ApplyCurrentValues(tblcallrepository);
               //db.SaveChanges();

               //write record to callque so we dont have to wait for IVRDM to hit
               IVRMaster_VoxeoEntities dbMaster = new IVRMaster_VoxeoEntities(SessionVars.Session_IVRMasterConnectString);
               tblCallQue tblcallque = new tblCallQue();
               tblcallque.ProjectCode = SessionVars.Session_ProjectCode;
               tblcallque.PhoneNumber = SessionVars.Session_PriPhone;
               tblcallque.IVRStartDate = DateTime.Now.AddDays(-1);
               tblcallque.IVRStopDate = DateTime.Now.AddDays(1);
               tblcallque.CallerID = "7208577900";
               tblcallque.RepositoryID = tblcallrepository.RepositoryID;
               tblcallque.AnswerTimeout = 30;
               tblcallque.Active = true; 
               tblcallque.Mon_StartTime = "0800";
               tblcallque.Mon_StopTime = "2000";
               tblcallque.Tue_StartTime = "0800";
               tblcallque.Tue_StopTime = "2000";
               tblcallque.Wed_StartTime = "0800";
               tblcallque.Wed_StopTime = "2000";
               tblcallque.Thu_StartTime = "0800";
               tblcallque.Thu_StopTime = "2000";
               tblcallque.Fri_StartTime = "0800";
               tblcallque.Fri_StopTime = "2000";
               tblcallque.Sat_StartTime = "0800";
               tblcallque.Sat_StopTime = "2000";
               tblcallque.Sun_StartTime = "0800";
               tblcallque.Sun_StopTime = "2000";
               tblcallque.TextMessage = tblcalltype.TextMessage;
               tblcallque.ManuallyTriggerCall = true;
               tblcallque.Debug = false; 
               dbMaster.tblCallQues.AddObject(tblcallque);
               dbMaster.SaveChanges();
           }