예제 #1
0
 /// <summary>
 /// Method responsible for raising the Updating event
 /// </summary>
 protected virtual void OnUpdating(EntityCancelEventArgs e)
 {
     if (Updating != null)
     {
         Updating(this, e);
     }
 }
예제 #2
0
 /// <summary>
 /// Method responsible for raising the Saving event
 /// </summary>
 protected virtual void OnSaving(EntityCancelEventArgs e)
 {
     if (Saving != null)
     {
         Saving(this, e);
     }
 }
예제 #3
0
 /// <summary>
 /// Method responsible for raising the Inserting event
 /// </summary>
 protected virtual void OnInserting(EntityCancelEventArgs e)
 {
     if (Inserting != null)
     {
         Inserting(this, e);
     }
 }
예제 #4
0
 /// <summary>
 /// Method responsible for raising the Deleting event
 /// </summary>
 protected virtual void OnDeleting(EntityCancelEventArgs e)
 {
     if (Deleting != null)
     {
         Deleting(this, e);
     }
 }
예제 #5
0
        /// <summary>
        /// Persists a Customer object to the data store. This is
        /// internal, and is used for recursive saves within a transaction.
        /// </summary>
        /// <param name="helper">The data connection helper</param>
        public override void Save(SqlHelper helper)
        {
            EntityCancelEventArgs e = new EntityCancelEventArgs(this, helper);

            bool isSavingEntity = false;

            EnsureParentProperties();

            OnSaveStarting(e);

            if (!e.Cancel)
            {
                if (IsNew || IsDirty || IsDeleted)
                {
                    isSavingEntity = true;

                    OnSaving(e);

                    this.Validate(helper);
                    if ((!this.IsDeleted) && (this.ValidationErrors.Count > 0))
                    {
                        throw new EntityException("Validation failed.", this, helper);
                    }

                    if (!e.Cancel)
                    {
                        if (this.IsDeleted)
                        {
                            this.Delete(helper);
                            return;
                        }

                        if (this.IsDirty)
                        {
                            if (this.IsNew)
                            {
                                this.Insert(helper);
                            }
                            else
                            {
                                this.Update(helper);
                            }
                        }
                    }
                }

                if (!e.Cancel)
                {
                    UpdateChildren(helper, UpdateType.Save);

                    if (isSavingEntity)
                    {
                        OnSaved(new EntityEventArgs(this, helper));
                    }
                }

                OnSaveFinished(new EntityEventArgs(this, helper));
            }
        }
예제 #6
0
        /// <summary>
        /// Deletes a Customer object from the data store. This is
        /// internal, and is used for deletes within a transaction.
        /// </summary>
        /// <param name="helper">The data connection helper</param>
        protected internal void Delete(SqlHelper helper)
        {
            EntityCancelEventArgs e = new EntityCancelEventArgs(this, helper);

            OnDeleting(e);

            if (!e.Cancel)
            {
                string commandText = this.DeleteSPName;

                System.Collections.Generic.List <SqlParameter> parameters = GetParameterList(ColumnType.PrimaryKeyColumn);

                helper.Execute(commandText, CommandType.StoredProcedure, parameters);

                OnDeleted(new EntityEventArgs(this, helper));
            }
        }
예제 #7
0
        ///// <summary>
        ///// Updates a Customer object to the data store. This is
        ///// protected, and is used for updates within a transaction.
        ///// </summary>
        ///// <param name="helper">The data connection helper</param>
        protected void Update(SqlHelper helper)
        {
            EntityCancelEventArgs e = new EntityCancelEventArgs(this, helper);

            OnUpdating(e);

            if (!e.Cancel)
            {
                string commandText = this.UpdateSPName;

                System.Collections.Generic.List <SqlParameter> parameters = GetParameterList(ColumnType.DatabaseColumn);

                using (IDataReader reader = helper.ExecuteDataReader(commandText, CommandType.StoredProcedure, parameters))
                {
                    if (reader.Read())
                    {
                        this.Initialize(reader);
                    }
                }

                OnUpdated(new EntityEventArgs(this, helper));
            }
        }