我正在对实体执行创建操作。该实体是存储过程的Function导入。没有抛出异常,但我在数据库中没有任何新东西。我检查了几次连接字符串,指向Dev环境,就像它应该的那样。我坚持ObjectResult<T>
上的断点,它点击并流过以返回View()。我还可以做些什么来调试/解决这个问题?
[HttpPost]
public ActionResult Create(Tracker_CreateUser_Result model)
{
string currentUser = Environment.UserDomainName + "\\" + Environment.UserName;
TrackerEntities context = new TrackerEntities();
model.User_Created_Date = DateTime.Now;
model.User_Created_Logon_Name = currentUser;
model.User_Updated_Logon_Name = currentUser;
model.User_Updated_Datetime = DateTime.Now;
System.Data.Objects.ObjectResult<Tracker_CreateUser_Result> result = context.Tracker_CreateUser(model.User_Name,model.User_Logon_Name,model.User_Token,model.User_Demo,model.User_Demo_Logon_Name,model.User_Interface,model.User_Status,model.User_Reason_for_Edit,model.User_Created_Logon_Name,model.User_Created_Date,model.User_Updated_Logon_Name,model.User_Updated_Datetime);
context.SaveChanges();//UPDATE
ViewBag.Message = "Successfully created user";
return View();
}
答案 0 :(得分:1)
添加实体后,您应该致电context.SaveChanges()
。
希望这会有所帮助:)