You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ability to refresh a context from the database #16491
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
@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.
@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?
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
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!
Activity
ajcvickers commentedon Jul 15, 2019
Triage: Putting this on the backlog to consider behaviors for DbContext in EF Core similar to
ObjectContext.Refreshin the old stack.audacity76 commentedon Jun 9, 2020
@ajcvickers Any update on this issue?
ajcvickers commentedon 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.
QutfulloOchilov commentedon Mar 3, 2021
@ajcvickers Any update on this issue?
DamirLisak commentedon Jan 12, 2023
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
ajcvickers commentedon Jan 13, 2023
@DamirLisak That's not decided yet.
DamirLisak commentedon 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?
roji commentedon 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.
hodaschiy commentedon Jun 16, 2024
@ajcvickers Any update on this issue?
roji commentedon Jun 16, 2024
@hodaschiy see the comment just above.
DamirLisak commentedon Nov 28, 2024
@knightmeister are you still waiting patiently for this feature or have you made your own implementation for it?
knightmeister commentedon Nov 29, 2024
@DamirLisak I ended up just using a message bus. Not elegant but it works.
dotnet#16491: Implemented legacy Merge-Option Feature from EF/4/5/6
* dotnet#16491: Implemented Merge-Option Feature from EF/4/5/6 tested…
DamirLisak commentedon 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!
dotnet#16491: Implemented legacy Merge-Option Feature from EF/4/5/6
* dotnet#16491: Implemented Merge-Option Feature from EF/4/5/6 tested…