コード例 #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
        /// 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));
            }
        }
コード例 #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.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));
            }
        }