Home > Net >  EntityFrameworkCore to use and is not the same as in my imagination
EntityFrameworkCore to use and is not the same as in my imagination

Time:05-21

My program is running to save some records, data volume is small,
My wish is to load the application runtime database, put out all the data in the memory,
So I run the program to modify data in the memory, in has been detected by the ef,
When I SaveChanges (), update the data in the change to the database,

However, when I use the First () positioning data, found the program or to access the database,
I think this visit is completely unnecessary, because the data in memory,
Whether using EntityFrameworkCore usage as I described above?

That is, read only once, the data change, save,
Search data don't access the database again, because there are data in memory,

CodePudding user response:

Ha, last time there was a stick that how to always read cache, how to read the database every time,
This post is just like that is on the contrary,

You should consider whether the data tracking, or the life cycle of EF context

CodePudding user response:

reference 1/f, nan peony reply:
ha, last time there was a stick that how to always read cache, how to read the database every time like this that is on the contrary, you should consider whether there is a tracking, data or EF context lifecycle
could you specific, I need to read it only once in database, the remaining read cache, all with the job of tracking,

CodePudding user response:

Put out all data in the memory
-> All out this way is not recommended for use, put it in memory is ToList operation, rather than return to IQueryable interface

CodePudding user response:

The
reference 3 floor exception92 response:
put out all the data in the memory
-> Are out of this approach is not recommended for use, in the memory is ToList operation, rather than return to IQueryable interface
in this case, the data assignment when you need to do 2 times, record and assign a value orientation, also need to access the database query, I the amount of data is small, all removed do tracking, is can't do?

CodePudding user response:

Database query results List I know, as long as ToList (),
That after modification of the List in my memory, also can turn back, again to update the database?

CodePudding user response:

refer to the fifth floor Chinese naming advocate response:
database query results List I know, as long as ToList (),
That after modification of the List in my memory, also can turn back, again to update the database?


This depends on how this list over, if causing them to become disconnected entities will cause your problem description

Official document with related description
  •  Tags:  
  • C#
  • Related