private void Child_Update(Category category, SqlConnection connection)
        {
            bool cancel = false;
            OnChildUpdating(category, connection, ref cancel);
            if (cancel) return;

            if(connection.State != ConnectionState.Open) connection.Open();
            const string commandText = "UPDATE [dbo].[Product] SET [ProductId] = @p_ProductId, [CategoryId] = @p_CategoryId, [Name] = @p_Name, [Descn] = @p_Descn, [Image] = @p_Image WHERE [ProductId] = @p_OriginalProductId; SELECT [ProductId] FROM [dbo].[Product] WHERE [ProductId] = @p_OriginalProductId";
            using(var command = new SqlCommand(commandText, connection))
            {
                command.Parameters.AddWithValue("@p_OriginalProductId", this.OriginalProductId);
                command.Parameters.AddWithValue("@p_ProductId", this.ProductId);
                command.Parameters.AddWithValue("@p_CategoryId", category != null ? category.CategoryId : this.CategoryId);
                command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(this.Description));
                command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image));

                // 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 foreign keys values. This code will update the values passed in from the parent only if no errors occurred after executing the query.
                if(category != null && category.CategoryId != this.CategoryId)
                    LoadProperty(_categoryIdProperty, category.CategoryId);

                // Update non-identity primary key value.
                LoadProperty(_originalProductIdProperty, this.ProductId);
            }
    
            FieldManager.UpdateChildren(this, null, connection);

            OnChildUpdated();
        }
        private void Child_Insert(Category category, SqlConnection connection)
        {
            bool cancel = false;
            OnChildInserting(category, connection, ref cancel);
            if (cancel) return;

            if(connection.State != ConnectionState.Open) connection.Open();
            const string commandText = "INSERT INTO [dbo].[Product] ([ProductId], [CategoryId], [Name], [Descn], [Image]) VALUES (@p_ProductId, @p_CategoryId, @p_Name, @p_Descn, @p_Image)";
            using(var command = new SqlCommand(commandText, connection))
            {
                command.Parameters.AddWithValue("@p_ProductId", this.ProductId);
                command.Parameters.AddWithValue("@p_CategoryId", category != null ? category.CategoryId : this.CategoryId);
                command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(this.Description));
                command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image));

                //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 foreign keys values. This code will update the values passed in from the parent only if no errors occurred after executing the query.
                if(category != null && category.CategoryId != this.CategoryId)
                    LoadProperty(_categoryIdProperty, category.CategoryId);

                // Update the original non-identity primary key value.
                LoadProperty(_originalProductIdProperty, this.ProductId);
            }
            
            // A child relationship exists on this Business Object but its type is not a child type (E.G. EditableChild). 
            // TODO: Please override OnChildInserted() and insert this child manually.
            // FieldManager.UpdateChildren(this, null, connection);

            OnChildInserted();
        }