如何使用ObjectContext编辑JQGrid目的或任何任务



由于我通过所有JQGrid CRUD教程基本上涵盖了DBContext方法,而不是使用ObjectContext。我获取的代码来自此链接中给出的教程:http://www.c-sharpcorner.com/article/performing-cruding-crud--operation-using-jqgrid-in-asp-net-mvc/

public string Edit(StudentMaster Model)  
{  
    ApplicationDbContext db = new ApplicationDbContext();  
string msg;  
try  
{  
    if (ModelState.IsValid)  
    {  
        db.Entry(Model).State = EntityState.Modified;  
        db.SaveChanges();  
        msg = "Saved Successfully";  
    }  
    else  
    {  
        msg = "Validation data not successfully";  
    }  
}  
catch (Exception ex)  
{  
    msg = "Error occured:" + ex.Message;  
}  
return msg;  
}  

是否有任何解决方案将其更改为ObjectContext方法?我的objectContext是

ECONSOVEntities1 db = new ECONSOVEntities1();

基本上我需要更改的部分才是此部分仅在我没记错的情况下。

 if (ModelState.IsValid)  
    {  
        db.Entry(Model).State = EntityState.Modified;  
        db.SaveChanges();  
        msg = "Saved Successfully";  
    }

如果有与我相同的问题,也可以包括它,这样我就可以轻松地引用那里,谢谢。

我想我已经得到答案大声笑...http://www.entityframeworktutorial.net/update-entity-in-entity-framework.aspx

using (SchoolDBContext newCtx = new SchoolDBContext())
{
    newCtx.Students.Attach(stud);
    newCtx.ObjectStateManager.ChangeObjectState(stud, System.Data.EntityState.Modified);        
    newCtx.SaveChanges();
}

相关内容

最新更新