I have an action method that gets a list of items containing updated values. The fact is that I only want to update a couple of fields (by e-mail or by phone), and not by full recording. The code below seems to do what I need, but is there a better or updated way to do this using EF 5? Sometimes I see people using .Find instead of Attach, etc.
public ActionResult Update(IEnumerable<GenericTable> items) { using (var gEntities = new genericEntities()) { foreach (var GenericTable in items) { gEntities.GenericTable.Attach(GenericTable); gEntities.Entry(GenericTable).Property(x => x.EmailAddress).IsModified = true; gEntities.Entry(GenericTable).Property(x => x.PhoneNumber).IsModified = true; } gEntities.SaveChanges(); }
Here I directly indicate the EF email address. And the phone number changes every time, but in practice it is one or the other, is there a way to detect only changed columns / properties?
thanks
source share