Kamran Teymurov
Kamran Teymurov

Reputation: 25

.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.

Upvotes: 1

Views: 218

Answers (2)

Shahid Muhammad
Shahid Muhammad

Reputation: 17

Before saving changes update the table something like that

.Update(x => x.Id== ID, object); and then

save changes.

Upvotes: -1

Nagaraj Raveendran
Nagaraj Raveendran

Reputation: 1220

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();

Upvotes: 2

Related Questions