I'm trying to revert Context changes using the Context.Refresh method but It seems like Refresh is not a member of Context.
I'm using the Microsoft ADO.NET Entity Framework 4.1 RC version.
Any idea?
To refresh an entity definition: Right-click the Entities folder and select Refresh Entity.
DbContext generally represents a database connection and a set of tables. DbSet is used to represent a table. Your code sample doesn't fit the expected pattern.
A DbContext instance represents a session with the database and can be used to query and save instances of your entities. DbContext is a combination of the Unit Of Work and Repository patterns. Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance.
This can be achieved in several ways: setting the EntityState for the entity explicitly; using the DbContext. Update method (which is new in EF Core); using the DbContext. Attach method and then "walking the object graph" to set the state of individual properties within the graph explicitly.
You are likely looking at a DbContext
, which does not have a Refresh
method. You can use the IObjectContextAdapter
interface to get the underlying ObjectContext
, and call Refresh on that.
var objectContext = ((IObjectContextAdapter)context).ObjectContext;
You can also use the Reload function on the Proxy Objects... Here is a sample to reload all modified objects:
var modifiedEntries = context.ChangeTracker.Entries()
.Where(e => e.State == EntityState.Modified);
foreach (var modifiedEntry in modifiedEntries) {
modifiedEntry.Reload();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With