Skip to content

Entity Framework Core ObjectContext.Refresh equivalent? #11706

Closed as duplicate

Description

@viveknuna

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?

Activity

  1. ajcvickers commented on Apr 17, 2018

    @ajcvickers
    Contributor

    @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.

  2. viveknuna commented on Apr 17, 2018

    @viveknuna
    Author

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

  3. ajcvickers commented on Apr 17, 2018

    @ajcvickers
    Contributor

    @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.

  4. ajcvickers commented on Apr 18, 2018

    @ajcvickers
    Contributor

    Closing as duplicate of #2296

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions