Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

entity framework core discard changes

public void RejectChanges()
    {
        foreach (var entry in ChangeTracker.Entries())
        {
            switch (entry.State)
            {
                case EntityState.Modified:
                case EntityState.Deleted:
                    entry.State = EntityState.Modified; //Revert changes made to deleted entity.
                    entry.State = EntityState.Unchanged;
                    break;
                case EntityState.Added:
                    entry.State = EntityState.Detached;
                    break;
            }
        }
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #entity #framework #core #discard
ADD COMMENT
Topic
Name
6+1 =