I want to update only one column in a table. I have to change value of active column to false. I'm using Entity framework. Following is the code that I tried for it:
public void DeleteUser(string userid, string siteid) { var user = new User(){UserId = userid, SiteId= siteid, Active = false}; //Changing Active to false, orignially true db_context.Users.Attach(user); db_context.Configuration.ValidateOnSaveEnabled = false; db_context.Entry(user).Property(x => x.Active).IsModified = true; db_context.SaveChanges(); db_context.Configuration.ValidateOnSaveEnabled = true; } I'm debugging the code. It reaches db_context.SaveChanges() and then throws following error:
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries. What's wrong here?