Search code examples
c#.netlinqframeworksentity

.net MVC entity framework SaveChanges does not working


I want to update my db like

                        var context = new asb_cardEntities3();
                        var query = db.WFileMaster.Where(q => q.ID == 
                                                        data.ID).FirstOrDefault();
                        query.SUBE = item.SUBE.ToString();
                        query.HES_NO = item.HES_NO.ToString();
                        query.DVZ_KOD = item.DVZ_KOD.ToString();
                        query.TUTAR = item.TUTAR.ToString();

                        //context.Entry(query).State = SUBE.Modified;
                        context.SaveChanges();

this, I did not get any error (all data come) I am new in this framework, I think problem is in context. But I did not find any solution.


Solution

  • Please change db to context while retrieving the record in the second line.

    var context = new asb_cardEntities3();
    var query = context.WFileMaster.Where(q => q.ID == data.ID).FirstOrDefault();
    query.SUBE = item.SUBE.ToString();
    query.HES_NO = item.HES_NO.ToString();
    query.DVZ_KOD = item.DVZ_KOD.ToString();
    query.TUTAR = item.TUTAR.ToString();
    
    context.SaveChanges();