Beispiel #1
0
        /// <summary>
        /// Inserts data into the data base using the information in the current
        ///    CSLA editable child business object of type <see cref="Category"/>
        /// </summary>
        /// <returns></returns>
        private void Child_Insert(SqlConnection connection)
        {
            bool cancel = false;

            OnChildInserting(connection, ref cancel);
            if (cancel)
            {
                return;
            }

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }
            using (var command = new SqlCommand("[dbo].[CSLA_Category_Insert]", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@p_CategoryId", this.CategoryId);
                command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(this.Description));

                command.ExecuteNonQuery();

                // Update the original non-identity primary key value.
                LoadProperty(_originalCategoryIdProperty, this.CategoryId);
            }

            OnChildInserted();
        }
Beispiel #2
0
        /// <summary>
        /// Updates the corresponding record in the data base with the information in the current
        ///    CSLA editable child business object of type <see cref="Category"/>
        /// </summary>
        /// <returns></returns>
        private void Child_Update(SqlConnection connection)
        {
            bool cancel = false;

            OnChildUpdating(connection, ref cancel);
            if (cancel)
            {
                return;
            }

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }
            using (var command = new SqlCommand("[dbo].[CSLA_Category_Update]", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@p_OriginalCategoryId", this.OriginalCategoryId);
                command.Parameters.AddWithValue("@p_CategoryId", this.CategoryId);
                command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(this.Description));

                //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                int result = command.ExecuteNonQuery();
                if (result == 0)
                {
                    throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                }

                // Update non-identity primary key value.
                LoadProperty(_categoryIdProperty, (System.String)command.Parameters["@p_CategoryId"].Value);

                // Update non-identity primary key value.
                LoadProperty(_originalCategoryIdProperty, this.CategoryId);
            }

            OnChildUpdated();
        }