简体   繁体   中英

How do I change the properties of database item through Entity Framework?

I would like to save the changes made to an object's properties that is saved in the DB through Entity Framework so that the id-s do not change only the properties. I tried removing it and adding it again but I get the following error: System.InvalidOperationException: 'The object cannot be deleted because it was not found in the ObjectStateManager.' I tried to set the Entity's state to modified but I get an error saying the id-s conflict with another db item (the one I want to modify, I want it to stay the same). I have not seen any modification done before so I have no idea how to do it.

Thanks for the advice

  1. Get the object from the database context.
  2. Modify the object properties.
  3. Save changes in the database context (eg _yourContext.SaveChanges() ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM