コード例 #1
0
        /// <summary>
        /// Handles the property changing event sent from child object.
        /// </summary>
        /// <param name="sender">child object</param>
        /// <param name="e">Property Changing arguements</param>
        private void PropertyChanging(object sender, PropertyChangingEventArgs e)
        {
            // Ignore events if syncronising with DB
            if (_isSyncronisingWithDB == true)
            {
                return;
            }

            // Do a check here to make sure that the entity is not change if it is supposed to be deleted
            if (this.LINQEntityState == EntityState.Deleted || this.LINQEntityState == EntityState.CancelNew)
            {
                throw new ApplicationException("You cannot modify a deleted entity");
            }

            // If it's a change tracked object thats in "Original" state
            // grab a copy of the object incase it's going to be modified
            if (this.LINQEntityState == EntityState.Original && LINQEntityKeepOriginal == true && LINQEntityOriginalValue == null)
            {
                _originalEntityValueTemp = LINQEntityBase.ShallowCopy(this);
            }
        }
コード例 #2
0
        /// <summary>
        /// Indicates that the entity will Update the database.
        /// </summary>
        /// <param name="OriginalValue">
        /// Sets/Overrides the original value of the entity.
        /// The entity value passed in should be an earlier shallow copy of the entity.
        /// This value can be set to null to indicate if the original entity value should be removed if it exists from a previous modification.
        /// </param>
        public void SetAsUpdateOnSubmit(LINQEntityBase OriginalValue)
        {
            if (this.LINQEntityState == EntityState.Detached)
            {
                throw new ApplicationException("You cannot change the Entity State from 'Detached' to 'Modified'");
            }

            if (this.LINQEntityState == EntityState.NotTracked)
            {
                throw new ApplicationException("You cannot change the Entity State when the Entity is not change tracked");
            }

            if (OriginalValue != null)
            {
                this._originalEntityValue = LINQEntityBase.ShallowCopy(this);
            }
            else
            {
                this._originalEntityValue = null;
            }

            this.LINQEntityState = EntityState.Modified;
        }