NullVoxPopuli
NullVoxPopuli

Reputation: 65143

How do I reload a model in Entity Framework 7?

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.

Upvotes: 2

Views: 1478

Answers (1)

Ricardo Peres
Ricardo Peres

Reputation: 14535

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.

Upvotes: 1

Related Questions