Exemplo n.º 1
0
        /// <summary>
        /// Merge differs from ApplyState in that its the merge of an entire
        /// entity as opposed to an arbitrary set (possibly subset) of values.
        /// Change tracking is suspended for the entity during the merge.
        /// </summary>
        /// <param name="otherEntity">The entity to merge into the current instance</param>
        /// <param name="loadBehavior">The load behavior to use</param>
        internal void Merge(Entity otherEntity, LoadBehavior loadBehavior)
        {
            if (loadBehavior == LoadBehavior.KeepCurrent)
            {
                return;
            }

            // set this flag so change tracking and edit enforcement
            // is suspended during the merge
            this._isMerging = true;

            IDictionary<string, object> otherState = otherEntity.ExtractState();
            this.ApplyState(otherState, loadBehavior);

            // after the merge update our original state based on the
            // load behavior selected
            if (this._originalValues != null)
            {
                if (loadBehavior == LoadBehavior.RefreshCurrent)
                {
                    // when refreshing, the entity should no longer be
                    // considered modfied, so we wipe out original values
                    this._originalValues = null;

                    if (this.EntityState == EntityState.Modified && this.CustomMethodInvocation == null && !this.HasChildChanges)
                    {
                        // we've just reverted all property edits. If we're not modified for
                        // any other reason, transition to Unmodified
                        this.EntityState = EntityState.Unmodified;
                    }
                }
                else
                {
                    this._originalValues = otherState;
                }
            }

            this._isMerging = false;
            this.OnLoaded(false);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Updates the original values with those of the specified
 /// entity. This method is used during refresh loading scenarios
 /// and conflict resolution to update original with the latest
 /// store values.
 /// </summary>
 /// <param name="entity">Entity with the new original state.</param>
 internal void UpdateOriginalValues(Entity entity)
 {
     Debug.Assert(this._originalValues != null, "Should only call UpdateOriginalValues if the entity has original values.");
     this._originalValues = entity.ExtractState();
 }