Editing an object in Entity Framework 6

asp.net-mvc entity-framework-6

Accepted Answer

The entity has to be updated, not reinserted:

public Employee Edit(Employee objEmployee) // Work on EDIT
{

    _entities.Employees.Attach(objEmployee);   
    var entity = _entities.Entry(objEmployee);  
    entry.State = EntityState.Modified;      // Mark as modified

    _entities.SaveChanges();
    return objEmployee;
}
0
10/22/2015 9:44:31 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow