Context does not track the retrieved user, so when you want to save the user back to the database must be attached to it and properly set user state, so that EF know it should update existing users not insert a new
Modify data in the data query cannot use AsNoTracking () (personal opinion)
CodePudding user response:
A blog, BBS is not soCodePudding user response:
??????????????????????????????CodePudding user response:
Can use AsNoTracking (), it represents the ef is not continue to track the state of the data,When you need to modify, so need to keep track and attach
public virtual T Update the entity (T)
{
DbEF. Set(). The Attach (entity);
DbEF. Entry(entity). State=EntityState. Modified;
DbEF. SaveChanges ();
Return the entity;
}
CodePudding user response:
Can use an entity class receives the value, then the entity class written to the database