I’m using EF4 for a webapp.
99% of the time I’m using LINQ to EF for my dataaccess, however one of the calls needs to be a sproc. It looks like this:
object[] params = { new SqlParameter("SomeId", someId),
new SqlParameter("OtherId", otherId)};
db.Database.ExecuteSqlCommand("dbo.spMySproc @SomeId, @OtherId", parms);
db.SaveChanges();
The sproc gets fired, the data gets updated. However, when EF’s data doesn’t get updated. I have learned that this is expected behavior. I have also learned that there is a .Refresh method on the ObjectContext, however my database entities object inherits from DbContext which doesn’t have this.
Is there a way to refresh my EF4 database after I’ve run this sproc?
Casey is more or less correct, but you can’t access it the way he indicates. You have cast the DbContext to an IObjectContextAdapter, then you can access the ObjectContext from that.
However, this is probably not the right way to go about things. I suspect that your problem is that you’re using a single DbContext in your app. DbContext is designed to do a single operation, then be destroyed. You should create a new DbContext for each operation, destorying it when finished..