Entity Framework Update

You can easly do it by using this code

using (var db = new EGAIS_RUEntities())
                db.Configuration.ValidateOnSaveEnabled = false;
                var _rec = new CONTRAGENT()
                    id = 1,
                    status = 3

                var entry = db.Entry(_rec);
                entry.Property(e => e.status).IsModified = true;

Please note, I set only value, that i wanted to cahnge. Another value is "id", that identifies the record.

Another interesting aspect is this

db.Configuration.ValidateOnSaveEnabled = false;

You will get an error if you don't set the fields with NOTNULL values.

another approach to it is
dbcontext.Entry(_rec).State = System.Data.Entity.EntityState.Modified;

No comments:

Post a Comment