I'm sure this is a duplicate but I can't find the question after scouring the internet. So if this is a duplicate, please just point me to the right one.
Question: How can I get entity framework to pickup changes in an entity in the database that happened from another source.
I have had many issues with this type of thing because of the DbContext cache not being updated.
Example:
Suppose I have 2 servers with the same schema. Both servers work together and both use the table Person.
- Server A creates Person
Jackwith an age of 21, saving it to the DB.Jackis cached in Server A's DbContext. - Server B fetches
Jackfrom the DB after Server A creates it. Then, Server B updatesJackto up the age to 22, saving it to the DB. - A request for
Jackis made to Server A. So Server A's DbContext responds with the version ofJackthat is in it's cache... with age still at 21.
I find it hard to believe that there's not a way for Server A's DbContext to re-fetch the record. I feel like this ability should be baked in to Entity Framework. If not, then what are my other options?
One option I thought of was to just tell Entity Framework not to use the cache. Is this possible?