Reputation: 18228
I have the following context:
public class DataContext : DbContext
{
/// <summary>
/// Gets or sets Addresses.
/// </summary>
public DbSet<Address> Addresses { get; set; }
/// <summary>
/// Gets or sets Users.
/// </summary>
public DbSet<Users> Users { get; set; }
}
I my application user may change data in say user data and then he may want to cancel changes. The best way to do this, is to refresh the DataContext
from the database. But DbContext
has no Refresh
method. How can I refresh my DataContext
?
Upvotes: 4
Views: 6681
Reputation: 32447
You can reload the entity from the database as follows.
context.Entry(user).Reload();
Or you can try out the methods described in this question.
Upvotes: 3