Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Framework Core ObjectContext.Refresh equivalent? #11706

Closed
viveknuna opened this issue Apr 17, 2018 · 4 comments
Closed

Entity Framework Core ObjectContext.Refresh equivalent? #11706

viveknuna opened this issue Apr 17, 2018 · 4 comments

Comments

@viveknuna
Copy link

With Entity Framework 6, it was possible to refresh all the context with the method : _myObjectContext.RefreshAsync(RefreshMode.StoreWins, GetAll())

I would like to do the same thing with Entity Framework Core, but I can't find the best way to do that.

So, what's the best way to refresh all the context with EF Core?

@ajcvickers
Copy link
Member

@viveknuna There isn't currently an equivalent in EF Core. context.Entry(foo).Reload() is currently the closest thing, but it only works on a single entity.

In general, we recommend using short-lived contexts that cover a single unit-of-work. This usually makes reloading from the store unnecessary.

@viveknuna
Copy link
Author

Could you please explain “short-lived contexts that cover a single unit-of-work”. Please provide sample code if possible.

@ajcvickers
Copy link
Member

@viveknuna That is, create a context instance, query for the relevant entities, make changes, save changes, dispose of the context. See https://www.martinfowler.com/eaaCatalog/unitOfWork.html for info on the unit-of-work-pattern.

@ajcvickers
Copy link
Member

Closing as duplicate of #2296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants