/// <summary>
 /// Method responsible for raising the Updating event
 /// </summary>
 protected virtual void OnUpdating(EntityCancelEventArgs e)
 {
     if (Updating != null)
     {
         Updating(this, e);
     }
 }
 /// <summary>
 /// Method responsible for raising the Saving event
 /// </summary>
 protected virtual void OnSaving(EntityCancelEventArgs e)
 {
     if (Saving != null)
     {
         Saving(this, e);
     }
 }
 /// <summary>
 /// Method responsible for raising the Inserting event
 /// </summary>
 protected virtual void OnInserting(EntityCancelEventArgs e)
 {
     if (Inserting != null)
     {
         Inserting(this, e);
     }
 }
 /// <summary>
 /// Method responsible for raising the Deleting event
 /// </summary>
 protected virtual void OnDeleting(EntityCancelEventArgs e)
 {
     if (Deleting != null)
     {
         Deleting(this, e);
     }
 }
        /// <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));
            }
        }
        /// <summary>
        /// Deletes a Customer object from the data store. This is
        /// is used for deletes within a transaction.
        /// </summary>
        /// <param name="helper">The data connection helper</param>
        public void Delete(SqlHelper helper)
        {
            EntityCancelEventArgs e = new EntityCancelEventArgs(this, helper);

            OnDeleting(e);

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

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

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

                OnDeleted(new EntityEventArgs(this, helper));
            }
        }
        ///// <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.UpdateSqlStatement;

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

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

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