Home > Net >  Linq query data with AsNoTracking () in the modified entity submit not written to the database
Linq query data with AsNoTracking () in the modified entity submit not written to the database

Time:09-18

Entity Framework exposes many performance tuning options to help you optimize the performance of the application, the adjustment is one of the options. AsNoTracking (), through the optimization, you can tell your Entity Framework don't track the query results, which means that the Entity Framework not returned by the query Entity to perform any other handling or storage, but it also means that you must first attach these entities to to track diagram, in order to update them,
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 so

CodePudding 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
  • Related