private void Child_Update(Order order, SqlConnection connection) { bool cancel = false; OnChildUpdating(order, connection, ref cancel); if (cancel) return; if(connection.State != ConnectionState.Open) connection.Open(); using(var command = new SqlCommand("[dbo].[CSLA_LineItem_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalOrderId", order != null ? order.OrderId : this.OriginalOrderId); command.Parameters.AddWithValue("@p_OrderId", order != null ? order.OrderId : this.OrderId); command.Parameters.AddWithValue("@p_OriginalLineNum", this.OriginalLineNum); command.Parameters.AddWithValue("@p_LineNum", this.LineNum); command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_Quantity", this.Quantity); command.Parameters.AddWithValue("@p_UnitPrice", this.UnitPrice); //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(_orderIdProperty,(System.Int32)command.Parameters["@p_OrderId"].Value); // Update non-identity primary key value. LoadProperty(_lineNumProperty,(System.Int32)command.Parameters["@p_LineNum"].Value); // 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(order != null && order.OrderId != this.OrderId) LoadProperty(_orderIdProperty, order.OrderId); // Update non-identity primary key value. LoadProperty(_originalOrderIdProperty, this.OrderId); // Update non-identity primary key value. LoadProperty(_originalLineNumProperty, this.LineNum); } // A child relationship exists on this Business Object but its type is not a child type (E.G. EditableChild). // TODO: Please override OnChildUpdated() and update this child manually. // FieldManager.UpdateChildren(this, connection); OnChildUpdated(); }
private void Child_Insert(Order order, SqlConnection connection) { bool cancel = false; OnChildInserting(order, connection, ref cancel); if (cancel) return; if(connection.State != ConnectionState.Open) connection.Open(); using(var command = new SqlCommand("[dbo].[CSLA_LineItem_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OrderId", order != null ? order.OrderId : this.OrderId); command.Parameters.AddWithValue("@p_LineNum", this.LineNum); command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_Quantity", this.Quantity); command.Parameters.AddWithValue("@p_UnitPrice", this.UnitPrice); command.ExecuteNonQuery(); // 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(order != null && order.OrderId != this.OrderId) LoadProperty(_orderIdProperty, order.OrderId); // Update the original non-identity primary key value. LoadProperty(_originalOrderIdProperty, this.OrderId); // Update the original non-identity primary key value. LoadProperty(_originalLineNumProperty, this.LineNum); } // 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, connection); OnChildInserted(); }