我正在使用MVC应用程序。context.SaveChanges()不持久化数据库中的数据
当我调用context.SaveChanges来更新特定的记录。更新未在数据库中注册。我也没有得到任何运行时错误。所有通知是我的记录没有更新。我仍然看到相同的值。插入功能完美地工作。
enter code here
public Admission Update(int stuid){
VDData.VidyaDaanEntities context = new VDData.VidyaDaanEntities();
VDData.Student_Master studentmaster = new VDData.Student_Master();
studentmaster.Student_ID = stuid;
studentmaster.Student_First_Name = this.FirstName;
studentmaster.Student_Middle_Name = this.MiddleName;
studentmaster.Student_Last_Name = this.LastName;
studentmaster.Student_Address_1 = this.Address;
studentmaster.Student_Address_2 = this.Address2;
studentmaster.Student_City = this.City;
studentmaster.Student_State = this.State;
studentmaster.Student_Pin_Code = this.Pincode;
context.SaveChanges(); // here it wont give any kind of error. it runs sucessfully. }
你可以提供一些代码! – Akrem 2013-05-14 11:36:59
在保存更改之前是否更新模型? – Prashant16 2013-05-14 11:40:10
您是否附加了该实体?你可以在这里找到有用的东西http://msdn.microsoft.com/en-us/data/jj592676.aspx – vmeln 2013-05-14 13:05:24