/// <summary> /// Get change state by comparing old and new values. /// </summary> /// <param name="type">Type of values.</param> /// <param name="oldValue">Old value.</param> /// <param name="newValue">New value.</param> /// <returns></returns> public static ChangeState GetValueChangeSet(Type type, object oldValue, object newValue) { ChangeState state = new ChangeState(); state.ValueType = type; state.oldValue = oldValue; state.newValue = newValue; state.State = System.Data.EntityState.Unchanged; if (oldValue != newValue) { state.State = System.Data.EntityState.Modified; } bool oldIsEmpty = oldValue == null || oldValue == Activator.CreateInstance(type); bool newIsEmpty = newValue == null || newValue == Activator.CreateInstance(type); if (oldIsEmpty && !newIsEmpty) { state.State = System.Data.EntityState.Added; } if (newIsEmpty && !oldIsEmpty) { state.State = System.Data.EntityState.Deleted; } return(state); }
/// <summary> /// Get change state by comparing old and new values. /// </summary> /// <param name="type">Type of values.</param> /// <param name="oldValue">Old value.</param> /// <param name="newValue">New value.</param> /// <returns></returns> public static ChangeState GetValueChangeSet(Type type, object oldValue, object newValue) { ChangeState state = new ChangeState(); state.ValueType = type; state.oldValue = oldValue; state.newValue = newValue; state.State = System.Data.EntityState.Unchanged; if (oldValue != newValue) state.State = System.Data.EntityState.Modified; bool oldIsEmpty = oldValue == null || oldValue == Activator.CreateInstance(type); bool newIsEmpty = newValue == null || newValue == Activator.CreateInstance(type); if (oldIsEmpty && !newIsEmpty) state.State = System.Data.EntityState.Added; if (newIsEmpty && !oldIsEmpty) state.State = System.Data.EntityState.Deleted; return state; }