Hello. I have a table that I pull using EF from the database and pass to the ViewModel for editing (edit window). View displays a DataGrid, where binding is carried out to entity fields. Below View (edit window) 2 Save and Exit buttons. When you click on Save, I call the Update command and the local data is saved in the database. When you click on the exit, just close the window.
When you reopen the window, I do a Get command, but the data is taken not from the database but from the local storage. Those. changed data. Can I somehow undo all local changes?
If by example, the whole problem is described as:
//station.Name был равен Name1 var station= _unitOfWork.StationRepository.Get().First(); //поменяли в локальной коллекции без Update в БД station.Name = "NEWname"; //сделали запрос чтобы к БД (хочу предыдущее состояние) station = _unitOfWork.StationRepository.Get().First(); // но station.Name уже "NEWname"; Tell me how best to edit data from the database?
repository code
public class GenericRepository<TEntity> : IRepository<TEntity> where TEntity : class { protected CisDbContext Context { get; } protected DbSet<TEntity> DbSet { get; } public GenericRepository(CisDbContext context) { Context = context; DbSet = context.Set<TEntity>(); } public virtual IQueryable<TEntity> Get() { return DbSet; } } Screenshot of the changes made in the nested table (many to many). The UndoChanges method does not remove them.
