Refactoring EF6 to EF Core
<p>I've been attempting to refactor some EF6 code to EF Core 1 and have hit a small stumbling block. The code I'm attempting to convert is here:</p>

<p><a href="https://github.com/mehdime/DbContextScope" rel="nofollow">https://github.com/mehdime/DbContextScope</a></p>

<p>Everything is mostly fine but DbContextScope.cs in particular is proving tricky, e.g. this method (edited for brevity):</p>

<pre><code>        public void RefreshEntitiesInParentScope(IEnumerable entities)
    {
        foreach (IObjectContextAdapter contextInCurrentScope in 
            _dbContexts.InitializedDbContexts.Values)
        {
            var correspondingParentContext =
                _parentScope._dbContexts.InitializedDbContexts.Values
                    .SingleOrDefault(parentContext =&gt; 
                        parentContext.GetType() == contextInCurrentScope.GetType())
                           as IObjectContextAdapter;

            if (correspondingParentContext == null)
                continue;

            foreach (var toRefresh in entities)
            {
                ObjectStateEntry stateInCurrentScope;
                if (contextInCurrentScope.ObjectContext.ObjectStateManager
                        .TryGetObjectStateEntry(toRefresh, out stateInCurrentScope))
                {
                    var key = stateInCurrentScope.EntityKey;

                    ObjectStateEntry stateInParentScope;
                    if (correspondingParentContext.ObjectContext.ObjectStateManager
                       .TryGetObjectStateEntry(key, out stateInParentScope))
                    {
                        if (stateInParentScope.State == EntityState.Unchanged)
                        {
                            correspondingParentContext.ObjectContext.Refresh(
                                RefreshMode.StoreWins, stateInParentScope.Entity);
                        }
                    }
                }
            }
        }
    }
</code></pre>

<p>Questions.</p>

<p>Firstly, I know I can replace ObjectContext.ObjectStateManager with the new ChangeTracker but want to ensure that the entry I obtain is obtained correctly.How would the following line translate in EF Core?</p>

<pre><code>contextInCurrentScope.ObjectContext.ObjectStateManager
    .TryGetObjectStateEntry(toRefresh, out stateInCurrentScope)
</code></pre>

<p>Secondly, what is the equivalent of this in EF Core?</p>

<pre><code>correspondingParentContext.ObjectContext.Refresh
</code></pre>

<p>Thanks!</p>

<p>P.s. There are many helpful comments in the source at the GitHub repo above.</p>