Skip to content

Ability to refresh a context from the database #16491

Description

@knightmeister

I'm raising this as I've seen #11706 and #2296 are closed.

I require this functionality for GUI applications, for which EF Core is a viable target - specifically via Xamarin and UWP.

It is possible with EF6 to refresh the context by using Refresh(RefreshMode.StoreWins)

I totally understand that contexts are suggested per-unit of work however GUI applications have long living components (such as the main screen) for which a unit of work isn't suitable.

At this stage I have implemented an internal message bus which indicates when a single entity should be reloaded, but it would be nice to be able to refresh the store and all tracked entities in EF Core.

Activity

  1. added this to the Backlog milestone on Jul 15, 2019
  2. ajcvickers commented on Jul 15, 2019

    @ajcvickers
    Contributor

    Triage: Putting this on the backlog to consider behaviors for DbContext in EF Core similar to ObjectContext.Refresh in the old stack.

  3. audacity76 commented on Jun 9, 2020

    @audacity76

    @ajcvickers Any update on this issue?

  4. ajcvickers commented on Jun 9, 2020

    @ajcvickers
    Contributor

    @audacity76 This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 5.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

  5. QutfulloOchilov commented on Mar 3, 2021

    @QutfulloOchilov

    @ajcvickers Any update on this issue?

  6. DamirLisak commented on Jan 12, 2023

    @DamirLisak

    Will it be also possible to refresh only the affected objects that have been queried from the database like in EF 4 ?
    In a similar way like
    https://learn.microsoft.com/en-us/dotnet/api/system.data.objects.objectquery-1.execute?view=netframework-4.8.1

    query.Include(c => c.RelatedData)...;
    query.MergeOption = MergeOption.OverwriteChanges; // or
    query.Execute(MergeOption.OverwriteChanges);
    
    
  7. ajcvickers commented on Jan 13, 2023

    @ajcvickers
    Contributor

    @DamirLisak That's not decided yet.

  8. DamirLisak commented on Apr 5, 2023

    @DamirLisak

    @ajcvickers When can we expect a decision? ( I'm asking because we urgently need this feature ;-) )
    If not, do you have a suggestion for a "MergeOption-Workaround" for refreshing entities?

  9. roji commented on Apr 5, 2023

    @roji
    Member

    This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 8.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.

  10. hodaschiy commented on Jun 16, 2024

    @hodaschiy

    @ajcvickers Any update on this issue?

  11. roji commented on Jun 16, 2024

    @roji
    Member

    @hodaschiy see the comment just above.

  12. DamirLisak commented on Nov 28, 2024

    @DamirLisak

    @knightmeister are you still waiting patiently for this feature or have you made your own implementation for it?

  13. knightmeister commented on Nov 29, 2024

    @knightmeister
    Author

    @DamirLisak I ended up just using a message bus. Not elegant but it works.

  14. added theissue type on Jun 15, 2025
  15. added 2 commits that reference this issue on Aug 9, 2025
  16. DamirLisak commented on Aug 12, 2025

    @DamirLisak

    I've added a new extension method

    public static IQueryable<T>Refresh<T>(this IQueryable<T> source, MergeOption mergeOption)

    which is very similar to the mechanism from EF4/5/6. I've tested it with my databases, and it works so far. However, I haven't written any unit tests for it.

    I've opened the following pull request and ask you @roji & @AndriySvyryd to incorporate this functionality into Main 🙏.
    #36556

    This extension isn't critical because it only hooks into the ShapedQueryCompilingExpressionVisitor at one point and is therefore backward compatible.

    I didn't consider adding a Refresh method to the DBContext using RefreshMode.ClientWins/StoreWins necessary, so I omitted it, as this can also be solved at the application level.

    After having to delve quite a bit into your code, I now understand why EF Core runs much more efficiently. Kudos to you for the way you built this!

  17. added 2 commits that reference this issue on Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions