Home > Net >  EF with edit data successfully, then refresh the page does not change
EF with edit data successfully, then refresh the page does not change

Time:11-18

EF with edit data successfully, then refresh the page does not change, tracking EF generated SQL statements, the SQL data is changed, then look at the data returned in vs do not change, very depressed,
Delete and add can be updated immediately, is editing, code show warrior

Public int the Modify (T model1, params string [] paraName)
{
Int iret=1;
Using (DbContext DB=new DBContextFactory () GetDbContext ())
{
DB. Set (). The Attach (model1);

DbEntityEntry entry=DB. Entry (model1);
Entry. The State=System. Data. The Entity. EntityState. Unchanged;

The foreach (string proName in paraName)
{
Entry. The Property (proName). IsModified=true;
}
Iret=the SaveChanges ();
}

}

Database has been changed, unless it is running system, the query can be seen, or remove the USING, then every query a NEW context, the updated query no problem, is there a better solution, or am I wrong there

CodePudding user response:

Entry. The State=System. Data. The Entity. EntityState. Unchanged;
Change to be Modified?

CodePudding user response:

Changed, too, strange strange!

CodePudding user response:

refer to the second floor qq_41805127 response:
changed, too, strange strange!

You are debugging to iret=DB. The SaveChanges (); After the iret and model1 didn't change?

CodePudding user response:

Iret have change, return 1, execute successfully, returns the front-end ajax. The data, and then the front in the request a refresh, query, return to get a list of the model in the collection does not change, the SQL trace SQL statement is no problem, context didn't release? And the context? , I use after using query, can refresh the success, that I am the only thread context, EF novice, a bit of a headache,

CodePudding user response:

reference 4 floor qq_41805127 response:
iret have change, return 1, execute successfully, returns the front-end ajax. The data, and then the front in the request a refresh, query, return to get a list of the model in the collection does not change, the SQL trace SQL statement is no problem, context didn't release? And the context? , I use after using query, can refresh the success, that I am the only thread context, EF novice, a bit of a headache,

It depends on the new DBContextFactory (.) GetDbContext () is how to produce the dbcontext,
With new every time should be no problem,

CodePudding user response:

Generally speaking, each request should generate a new db

CodePudding user response:

Well, later I will NEW context, is solved

CodePudding user response:

MARK the

CodePudding user response:

Mark the

CodePudding user response:

Many times found that flexible high strength for the business system, EF actually generate controversy and delay time was quite obvious, must be used at the same time SQLHelper, avoid excessive reliance on internal friction framework,

CodePudding user response:

refer to 7th floor qq_41805127 response:
well, later I will NEW context, solves the

This is the key to using a global context, it is not the correct use of the EF, should use the local context,

Think EF after loading data at a time, or old data to be loaded again (although SQL is still on the database side), it is one of the characteristics of EF,
  • Related