user1014901
user1014901

Reputation: 159

dbcontext does not contain a definition for 'Refresh'

I'm working with the entity framework code first and am getting the following compilation error. dbcontext does not contain a definition for 'Refresh'. I have seen many examples where the Refresh method is being used. But when i add the Refresh method to my dbcontext I get a complilation error. I'm using the following namespaces.

using System.Data;
using System.Data.Entity;
using System.Data.Linq;

Am I missing one? I tried to look it up but did not find the namespace.

Upvotes: 14

Views: 16608

Answers (2)

Henk Holterman
Henk Holterman

Reputation: 273219

DbContext does indeed not have a Refresh() method.

The examples you saw were probably using ObjectContext.Refresh().

You can get one from the other:

 db = new MyDbContext())
 ...   
 var ctx = ((IObjectContextAdapter)db).ObjectContext;
 ctx.Refresh();

This question has more about the details and differences.

Upvotes: 30

Marc Gravell
Marc Gravell

Reputation: 1062745

LINQ-to-SQL has a confusingly similar DataContext class, that has this method.

Entity Framework: does not.

Upvotes: 1

Related Questions