Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WPF MVVM - Cancel ie Revert
Message
De
01/10/2019 14:46:56
 
 
À
27/09/2019 15:41:24
Information générale
Forum:
C#
Catégorie:
Entity Framework
Divers
Thread ID:
01671193
Message ID:
01671292
Vues:
42
hm...question, what is the best way?
Any idea, any other solution?

Thanks



I've solved on yet two other ways:

ViewModel class
...
void cancel()
        {
            if (personCollection.Count < 1 || personCollection == null)
            {
                _business.Cancel();
                PersonCollection = null;
                SelectedPerson = null;
            }
            else
            {
                int index = personCollection.IndexOf(_person);
                if (index < 0)
                    index = personCollection.Count - 1;
                _business.Cancel();
                GoToRowDG(index);
            }
        }
...

Business class
...
public void Cancel()
        {
            // 1. OK 
            //
            var changedEntries = _dbContext.ChangeTracker.Entries()
                .Where(x => x.State != EntityState.Unchanged).ToList();

            foreach (var entry in changedEntries)
            {
                switch (entry.State)
                {
                    case EntityState.Modified:
                        //entry.CurrentValues.SetValues(entry.OriginalValues);
                        entry.State = EntityState.Unchanged;
                        break;
                    case EntityState.Added:
                        entry.State = EntityState.Detached;
                        break;
                    case EntityState.Deleted:
                        entry.State = EntityState.Unchanged;
                        break;
                }
            }

            //2. OK
            //
            //var context = ((IObjectContextAdapter)_dbContext).ObjectContext;
            //var changedEntries = _dbContext.ChangeTracker.Entries()
            //    .Where(x => x.State != EntityState.Unchanged).ToList();
            //foreach (var change in changedEntries)
            //{
            //    if (change.State == EntityState.Modified)
            //    {
            //        context.Refresh(RefreshMode.StoreWins, change.Entity);
            //    }
            //    if (change.State == EntityState.Added)
            //    {
            //        context.Detach(change.Entity);
            //    }
            //}
}
...
hm...question, what is the best way?
Any idea, any other solution?


Hi ,

Best way for Revert ie Cancel

This problem I've solved on this way:

ViewModel class
...
public void cancel()
        {
            int ln = SelectedPerson.Id;
            int index = personCollection.IndexOf(_person);
            var operson = _business.FindPersonID(ln);

            personCollection[index] = operson;  
            SelectedPerson = operson; 
            GoToRowDG(index);
   
     }
...

Business class
...
internal Person FindPersonID(int lnid)                    
        {
            _dbContext = new PersonDB();
            var o =_dbContext.Person.Find(lnid);
            return o;
        }
is this good way for revert ie cancel ?

I've read and about RejectChanges or BeginEdit/CancelEdit, but I don't know how that can implemented for my example?

Thanks
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform