GeezerVison is showing github.com — Ability to refresh a context from the database · Issue #16491 · dotnet/efcore
Ability to refresh a context from the database #16491DescriptionI'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. Reacted by Sven, jaaywags, Mahfoud Bouabdallah, andre9349, José Luis Orihuela Conde, Thomas Hussey, Xriuk, Peter Kurhajec, Netta Shamir, clivingston2 and 29 more Activityajcvickers commented on Jul 15, 2019 Triage: Putting this on the backlog to consider behaviors for DbContext in EF Core similar to ObjectContext.Refresh in the old stack. audacity76 commented on Jun 9, 2020 Reacted by George Santana ajcvickers commented on Jun 9, 2020 @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. Reacted by George Santana QutfulloOchilov commented on Mar 3, 2021 DamirLisak commented on Jan 12, 2023 Reacted by Xriuk, Mario Žitković, Aleksandar Agincic, Boby, Peter Kurhajec, Damir Lisak, Marowinger, Karakol61, DaveCousineau, ldfreenet and 2 more ajcvickers commented on Jan 13, 2023 Reacted by Damir Lisak and Mario Žitković DamirLisak commented on Apr 5, 2023 @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? Reacted by Netta Shamir, Karakol61 and dhbprog roji commented on Apr 5, 2023 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. Reacted by Henrik Hoyer, Vanasis Baboomi, Byron Smith, dhbprog and Conor Dockry hodaschiy commented on Jun 16, 2024 roji commented on Jun 16, 2024 Reacted by Damir Lisak, Arthur Vickers and hodaschiy DamirLisak commented on Nov 28, 2024 @knightmeister are you still waiting patiently for this feature or have you made your own implementation for it? knightmeister commented on Nov 29, 2024 @DamirLisak I ended up just using a message bus. Not elegant but it works. DamirLisak commented on Aug 12, 2025 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!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|