Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 15 characters in body; edited body
Source Link
Maxsteel
  • 2.1k
  • 4
  • 32
  • 57

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 UsersUser(){UserId = userid, SiteId= siteid, Active = false}; //Changing Active to false, orignially true db_context.PlayerInfoesUsers.Attach(playuser); db_context.Configuration.ValidateOnSaveEnabled = false; db_context.Entry(playuser).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?


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 Users(){UserId = userid, SiteId= siteid, Active = false}; //Changing Active to false, orignially true db_context.PlayerInfoes.Attach(play); db_context.Configuration.ValidateOnSaveEnabled = false; db_context.Entry(play).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?


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?

Source Link
Maxsteel
  • 2.1k
  • 4
  • 32
  • 57

Unable to update column in Entity framework


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 Users(){UserId = userid, SiteId= siteid, Active = false}; //Changing Active to false, orignially true db_context.PlayerInfoes.Attach(play); db_context.Configuration.ValidateOnSaveEnabled = false; db_context.Entry(play).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?