How do I reload a model in Entity Framework 7?

c# caching entity-framework entity-framework-core

Question

I've read that in previous versions of the entity framework, you had access to a Reload() method, like this: Db.Entry<DatabaseModels.User>(_me).Reload();

I get an error from that saying that EntityEntry does not contain a definition for 'Reload'.

The reason why I even want to reload is from caching (or what I think is caching, and EF possibly not knowing when to invalidate the cache).

Example:

Load userA.
Create item that userA will own.
Try to access that new item through the relationship on the user. userA.Items returns empty
re-fetch userA from the database, and call the relationship, and the newly created item is in the association.

Not sure why that's happening, or if there is a way to get EF to be smarted about cache invalidation.

Accepted Answer

It isn't supported, but you can do it through code, by inspecting the metadata. See here an example: https://weblogs.asp.net/ricardoperes/implementing-missing-features-in-entity-framework-core.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why