How to update data in Entity Framework 4.1 code first

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, can modify the data in user data, and then he can discard the changes. The best way to do this is to update the DataContext from the database. But DbContext does not have a Refresh method. How to update my DataContext ?

+4
source share
1 answer

You can reload the object from the database as follows.

 context.Entry(user).Reload(); 

Or you can try the methods described in this question .

+3
source

Source: https://habr.com/ru/post/1388528/


All Articles