Refresh entity instance with DbContext

mare picture mare · Mar 7, 2011 · Viewed 34.7k times · Source

With EF4 CTP5 DbContext, what is the equivalent of this

    public void Refresh(Document instance)
    {
        _ctx.Refresh(RefreshMode.StoreWins, instance);
    }

I've tried this but it doesn't do the same thing, updating the instance

    public void Refresh(Document instance)
    {
        _ctx.ChangeTracker.DetectChanges();
    }

?

Answer

Ladislav Mrnka picture Ladislav Mrnka · Mar 7, 2011

You must use this:

public void Refresh(Document instance)
{
  _ctx.Entry<Document>(instance).Reload();
}