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); } FieldManager.UpdateChildren(this, connection); OnChildInserted(); }
protected override void DataPortal_Insert() { bool cancel = false; OnInserting(ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { 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(); using (BypassPropertyChecks) { } } LoadProperty(_originalCategoryIdProperty, this.CategoryId); FieldManager.UpdateChildren(this, connection); } OnInserted(); }
private void Child_Update(Product product, Supplier supplier, SqlConnection connection) { bool cancel = false; OnChildUpdating(product, supplier, connection, ref cancel); if (cancel) { return; } if (connection.State != ConnectionState.Open) { connection.Open(); } using (var command = new SqlCommand("[dbo].[CSLA_Item_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalItemId", this.OriginalItemId); command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_ProductId", product != null ? product.ProductId : this.ProductId); command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice)); command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost)); command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(supplier != null ? supplier.SuppId : this.Supplier)); command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status)); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); 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 non-identity primary key value. LoadProperty(_itemIdProperty, (System.String)command.Parameters["@p_ItemId"].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 (product != null && product.ProductId != this.ProductId) { LoadProperty(_productIdProperty, product.ProductId); } // 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 (supplier != null && supplier.SuppId != this.Supplier) { LoadProperty(_supplierProperty, supplier.SuppId); } // Update non-identity primary key value. LoadProperty(_originalItemIdProperty, this.ItemId); } // 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(); }
protected override void DataPortal_Insert() { bool cancel = false; OnInserting(ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Order_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OrderId", this.OrderId); command.Parameters["@p_OrderId"].Direction = ParameterDirection.Output; command.Parameters.AddWithValue("@p_UserId", this.UserId); command.Parameters.AddWithValue("@p_OrderDate", this.OrderDate); command.Parameters.AddWithValue("@p_ShipAddr1", this.ShipAddr1); command.Parameters.AddWithValue("@p_ShipAddr2", ADOHelper.NullCheck(this.ShipAddr2)); command.Parameters.AddWithValue("@p_ShipCity", this.ShipCity); command.Parameters.AddWithValue("@p_ShipState", this.ShipState); command.Parameters.AddWithValue("@p_ShipZip", this.ShipZip); command.Parameters.AddWithValue("@p_ShipCountry", this.ShipCountry); command.Parameters.AddWithValue("@p_BillAddr1", this.BillAddr1); command.Parameters.AddWithValue("@p_BillAddr2", ADOHelper.NullCheck(this.BillAddr2)); command.Parameters.AddWithValue("@p_BillCity", this.BillCity); command.Parameters.AddWithValue("@p_BillState", this.BillState); command.Parameters.AddWithValue("@p_BillZip", this.BillZip); command.Parameters.AddWithValue("@p_BillCountry", this.BillCountry); command.Parameters.AddWithValue("@p_Courier", this.Courier); command.Parameters.AddWithValue("@p_TotalPrice", this.TotalPrice); command.Parameters.AddWithValue("@p_BillToFirstName", this.BillToFirstName); command.Parameters.AddWithValue("@p_BillToLastName", this.BillToLastName); command.Parameters.AddWithValue("@p_ShipToFirstName", this.ShipToFirstName); command.Parameters.AddWithValue("@p_ShipToLastName", this.ShipToLastName); command.Parameters.AddWithValue("@p_AuthorizationNumber", this.AuthorizationNumber); command.Parameters.AddWithValue("@p_Locale", this.Locale); command.ExecuteNonQuery(); using (BypassPropertyChecks) { LoadProperty(_orderIdProperty, (System.Int32)command.Parameters["@p_OrderId"].Value); } } FieldManager.UpdateChildren(this, connection); } OnInserted(); }
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_Order_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OrderId", this.OrderId); command.Parameters.AddWithValue("@p_UserId", this.UserId); command.Parameters.AddWithValue("@p_OrderDate", this.OrderDate); command.Parameters.AddWithValue("@p_ShipAddr1", this.ShipAddr1); command.Parameters.AddWithValue("@p_ShipAddr2", ADOHelper.NullCheck(this.ShipAddr2)); command.Parameters.AddWithValue("@p_ShipCity", this.ShipCity); command.Parameters.AddWithValue("@p_ShipState", this.ShipState); command.Parameters.AddWithValue("@p_ShipZip", this.ShipZip); command.Parameters.AddWithValue("@p_ShipCountry", this.ShipCountry); command.Parameters.AddWithValue("@p_BillAddr1", this.BillAddr1); command.Parameters.AddWithValue("@p_BillAddr2", ADOHelper.NullCheck(this.BillAddr2)); command.Parameters.AddWithValue("@p_BillCity", this.BillCity); command.Parameters.AddWithValue("@p_BillState", this.BillState); command.Parameters.AddWithValue("@p_BillZip", this.BillZip); command.Parameters.AddWithValue("@p_BillCountry", this.BillCountry); command.Parameters.AddWithValue("@p_Courier", this.Courier); command.Parameters.AddWithValue("@p_TotalPrice", this.TotalPrice); command.Parameters.AddWithValue("@p_BillToFirstName", this.BillToFirstName); command.Parameters.AddWithValue("@p_BillToLastName", this.BillToLastName); command.Parameters.AddWithValue("@p_ShipToFirstName", this.ShipToFirstName); command.Parameters.AddWithValue("@p_ShipToLastName", this.ShipToLastName); command.Parameters.AddWithValue("@p_AuthorizationNumber", this.AuthorizationNumber); command.Parameters.AddWithValue("@p_Locale", this.Locale); //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."); } } FieldManager.UpdateChildren(this, connection); OnChildUpdated(); }
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_Order_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OrderId", this.OrderId); command.Parameters["@p_OrderId"].Direction = ParameterDirection.Output; command.Parameters.AddWithValue("@p_UserId", this.UserId); command.Parameters.AddWithValue("@p_OrderDate", this.OrderDate); command.Parameters.AddWithValue("@p_ShipAddr1", this.ShipAddr1); command.Parameters.AddWithValue("@p_ShipAddr2", ADOHelper.NullCheck(this.ShipAddr2)); command.Parameters.AddWithValue("@p_ShipCity", this.ShipCity); command.Parameters.AddWithValue("@p_ShipState", this.ShipState); command.Parameters.AddWithValue("@p_ShipZip", this.ShipZip); command.Parameters.AddWithValue("@p_ShipCountry", this.ShipCountry); command.Parameters.AddWithValue("@p_BillAddr1", this.BillAddr1); command.Parameters.AddWithValue("@p_BillAddr2", ADOHelper.NullCheck(this.BillAddr2)); command.Parameters.AddWithValue("@p_BillCity", this.BillCity); command.Parameters.AddWithValue("@p_BillState", this.BillState); command.Parameters.AddWithValue("@p_BillZip", this.BillZip); command.Parameters.AddWithValue("@p_BillCountry", this.BillCountry); command.Parameters.AddWithValue("@p_Courier", this.Courier); command.Parameters.AddWithValue("@p_TotalPrice", this.TotalPrice); command.Parameters.AddWithValue("@p_BillToFirstName", this.BillToFirstName); command.Parameters.AddWithValue("@p_BillToLastName", this.BillToLastName); command.Parameters.AddWithValue("@p_ShipToFirstName", this.ShipToFirstName); command.Parameters.AddWithValue("@p_ShipToLastName", this.ShipToLastName); command.Parameters.AddWithValue("@p_AuthorizationNumber", this.AuthorizationNumber); command.Parameters.AddWithValue("@p_Locale", this.Locale); command.ExecuteNonQuery(); // Update identity primary key value. LoadProperty(_orderIdProperty, (System.Int32)command.Parameters["@p_OrderId"].Value); } FieldManager.UpdateChildren(this, connection); OnChildInserted(); }
private void Child_Insert(Product product, Supplier supplier, SqlConnection connection) { bool cancel = false; OnChildInserting(product, supplier, connection, ref cancel); if (cancel) { return; } if (connection.State != ConnectionState.Open) { connection.Open(); } using (var command = new SqlCommand("[dbo].[CSLA_Item_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_ProductId", product != null ? product.ProductId : this.ProductId); command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice)); command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost)); command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(supplier != null ? supplier.SuppId : this.Supplier)); command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status)); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image)); 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 (product != null && product.ProductId != this.ProductId) { LoadProperty(_productIdProperty, product.ProductId); } // 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 (supplier != null && supplier.SuppId != this.Supplier) { LoadProperty(_supplierProperty, supplier.SuppId); } // Update the original non-identity primary key value. LoadProperty(_originalItemIdProperty, this.ItemId); } // 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(); }
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(); } using (var command = new SqlCommand("[dbo].[CSLA_Product_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; 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 non-identity primary key value. LoadProperty(_productIdProperty, (System.String)command.Parameters["@p_ProductId"].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 (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_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_Item_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalItemId", this.OriginalItemId); command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_ProductId", this.ProductId); command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice)); command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost)); command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(this.Supplier)); command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status)); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); 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 non-identity primary key value. LoadProperty(_itemIdProperty, (System.String)command.Parameters["@p_ItemId"].Value); // Update non-identity primary key value. LoadProperty(_originalItemIdProperty, this.ItemId); } FieldManager.UpdateChildren(this, 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(); } using (var command = new SqlCommand("[dbo].[CSLA_Product_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; 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)); 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 (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(); }
protected override void DataPortal_Insert() { bool cancel = false; OnInserting(ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_SuppId", this.SuppId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Status", this.Status); command.Parameters.AddWithValue("@p_Addr1", ADOHelper.NullCheck(this.Addr1)); command.Parameters.AddWithValue("@p_Addr2", ADOHelper.NullCheck(this.Addr2)); command.Parameters.AddWithValue("@p_City", ADOHelper.NullCheck(this.City)); command.Parameters.AddWithValue("@p_State", ADOHelper.NullCheck(this.State)); command.Parameters.AddWithValue("@p_Zip", ADOHelper.NullCheck(this.Zip)); command.Parameters.AddWithValue("@p_Phone", ADOHelper.NullCheck(this.Phone)); command.ExecuteNonQuery(); using (BypassPropertyChecks) { } } LoadProperty(_originalSuppIdProperty, this.SuppId); FieldManager.UpdateChildren(this, connection); } OnInserted(); }
protected override void DataPortal_Insert() { bool cancel = false; OnInserting(ref cancel); if (cancel) { return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Item_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_ProductId", this.ProductId); command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice)); command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost)); command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(this.Supplier)); command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status)); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image)); command.ExecuteNonQuery(); using (BypassPropertyChecks) { } } LoadProperty(_originalItemIdProperty, this.ItemId); FieldManager.UpdateChildren(this, connection); } OnInserted(); }
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_Item_Insert]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_ProductId", this.ProductId); command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice)); command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost)); command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(this.Supplier)); command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status)); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image)); command.ExecuteNonQuery(); // Update the original non-identity primary key value. LoadProperty(_originalItemIdProperty, this.ItemId); } FieldManager.UpdateChildren(this, connection); OnChildInserted(); }
protected override void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) { return; } if (OriginalSuppId != SuppId) { // Insert new child. Supplier item = new Supplier { SuppId = SuppId, Name = Name, Status = Status, Addr1 = Addr1, Addr2 = Addr2, City = City, State = State, Zip = Zip, Phone = Phone }; item = item.Save(); // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships. foreach (Item itemToUpdate in Items) { itemToUpdate.Supplier = SuppId; } // Create a new connection. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); FieldManager.UpdateChildren(this, connection); } // Delete the old. var criteria = new SupplierCriteria { SuppId = OriginalSuppId }; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalSuppId = SuppId; OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Supplier_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalSuppId", this.OriginalSuppId); command.Parameters.AddWithValue("@p_SuppId", this.SuppId); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); command.Parameters.AddWithValue("@p_Status", this.Status); command.Parameters.AddWithValue("@p_Addr1", ADOHelper.NullCheck(this.Addr1)); command.Parameters.AddWithValue("@p_Addr2", ADOHelper.NullCheck(this.Addr2)); command.Parameters.AddWithValue("@p_City", ADOHelper.NullCheck(this.City)); command.Parameters.AddWithValue("@p_State", ADOHelper.NullCheck(this.State)); command.Parameters.AddWithValue("@p_Zip", ADOHelper.NullCheck(this.Zip)); command.Parameters.AddWithValue("@p_Phone", ADOHelper.NullCheck(this.Phone)); //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."); } LoadProperty(_originalSuppIdProperty, this.SuppId); } FieldManager.UpdateChildren(this, connection); } OnUpdated(); }
protected override void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) { return; } if (OriginalItemId != ItemId) { // Insert new child. Item item = new Item { ItemId = ItemId, ProductId = ProductId, Status = Status, Name = Name, Image = Image }; if (ListPrice.HasValue) { item.ListPrice = ListPrice.Value; } if (UnitCost.HasValue) { item.UnitCost = UnitCost.Value; } if (Supplier.HasValue) { item.Supplier = Supplier.Value; } item = item.Save(); // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships. // Create a new connection. using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); FieldManager.UpdateChildren(this, connection); } // Delete the old. var criteria = new ItemCriteria { ItemId = OriginalItemId }; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalItemId = ItemId; OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (var command = new SqlCommand("[dbo].[CSLA_Item_Update]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_OriginalItemId", this.OriginalItemId); command.Parameters.AddWithValue("@p_ItemId", this.ItemId); command.Parameters.AddWithValue("@p_ProductId", this.ProductId); command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice)); command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost)); command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(this.Supplier)); command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status)); command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name)); 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."); } LoadProperty(_originalItemIdProperty, this.ItemId); } FieldManager.UpdateChildren(this, connection); } OnUpdated(); }