/// <summary> /// Update an existing row in the datasource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Categories object to update.</param> /// <remarks> /// After updating the datasource, the Northwind.Entities.Categories object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Update(TransactionManager transactionManager, Northwind.Entities.Categories entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Categories_Update", _useStoredProcedure); database.AddInParameter(commandWrapper, "@CategoryId", DbType.Int32, entity.CategoryId ); database.AddInParameter(commandWrapper, "@CategoryName", DbType.String, entity.CategoryName ); database.AddInParameter(commandWrapper, "@Description", DbType.String, entity.Description ); database.AddInParameter(commandWrapper, "@Picture", DbType.Binary, entity.Picture ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } //Stop Tracking Now that it has been updated and persisted. if (DataRepository.Provider.EnableEntityTracking) { EntityManager.StopTracking(entity.EntityTrackingKey); } entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Update an existing row in the datasource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.OrderDetails object to update.</param> /// <remarks> /// After updating the datasource, the Northwind.Entities.OrderDetails object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Update(TransactionManager transactionManager, Northwind.Entities.OrderDetails entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_OrderDetails_Update", _useStoredProcedure); database.AddInParameter(commandWrapper, "@OrderId", DbType.Int32, entity.OrderId ); database.AddInParameter(commandWrapper, "@OriginalOrderId", DbType.Int32, entity.OriginalOrderId); database.AddInParameter(commandWrapper, "@ProductId", DbType.Int32, entity.ProductId ); database.AddInParameter(commandWrapper, "@OriginalProductId", DbType.Int32, entity.OriginalProductId); database.AddInParameter(commandWrapper, "@UnitPrice", DbType.Currency, entity.UnitPrice ); database.AddInParameter(commandWrapper, "@Quantity", DbType.Int16, entity.Quantity ); database.AddInParameter(commandWrapper, "@Discount", DbType.Single, entity.Discount ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } //Stop Tracking Now that it has been updated and persisted. if (DataRepository.Provider.EnableEntityTracking) { EntityManager.StopTracking(entity.EntityTrackingKey); } entity.OriginalOrderId = entity.OrderId; entity.OriginalProductId = entity.ProductId; entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Inserts a Northwind.Entities.Region object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Region object to insert.</param> /// <remarks> /// After inserting into the datasource, the Northwind.Entities.Region object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Insert(TransactionManager transactionManager, Northwind.Entities.Region entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Region_Insert", _useStoredProcedure); database.AddInParameter(commandWrapper, "@RegionId", DbType.Int32, entity.RegionId ); database.AddInParameter(commandWrapper, "@RegionDescription", DbType.StringFixedLength, entity.RegionDescription ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } entity.OriginalRegionId = entity.RegionId; entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Inserts a Northwind.Entities.Categories object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Categories object to insert.</param> /// <remarks> /// After inserting into the datasource, the Northwind.Entities.Categories object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Insert(TransactionManager transactionManager, Northwind.Entities.Categories entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Categories_Insert", _useStoredProcedure); database.AddOutParameter(commandWrapper, "@CategoryId", DbType.Int32, 4); database.AddInParameter(commandWrapper, "@CategoryName", DbType.String, entity.CategoryName ); database.AddInParameter(commandWrapper, "@Description", DbType.String, entity.Description ); database.AddInParameter(commandWrapper, "@Picture", DbType.Binary, entity.Picture ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } object _categoryId = database.GetParameterValue(commandWrapper, "@CategoryId"); entity.CategoryId = (System.Int32)_categoryId; entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Update an existing row in the datasource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Employees object to update.</param> /// <remarks> /// After updating the datasource, the Northwind.Entities.Employees object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Update(TransactionManager transactionManager, Northwind.Entities.Employees entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Employees_Update", _useStoredProcedure); database.AddInParameter(commandWrapper, "@EmployeeId", DbType.Int32, entity.EmployeeId ); database.AddInParameter(commandWrapper, "@LastName", DbType.String, entity.LastName ); database.AddInParameter(commandWrapper, "@FirstName", DbType.String, entity.FirstName ); database.AddInParameter(commandWrapper, "@Title", DbType.String, entity.Title ); database.AddInParameter(commandWrapper, "@TitleOfCourtesy", DbType.String, entity.TitleOfCourtesy ); database.AddInParameter(commandWrapper, "@BirthDate", DbType.DateTime, (entity.BirthDate.HasValue ? (object) entity.BirthDate : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@HireDate", DbType.DateTime, (entity.HireDate.HasValue ? (object) entity.HireDate : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address ); database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City ); database.AddInParameter(commandWrapper, "@Region", DbType.String, entity.Region ); database.AddInParameter(commandWrapper, "@PostalCode", DbType.String, entity.PostalCode ); database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country ); database.AddInParameter(commandWrapper, "@HomePhone", DbType.String, entity.HomePhone ); database.AddInParameter(commandWrapper, "@Extension", DbType.String, entity.Extension ); database.AddInParameter(commandWrapper, "@Photo", DbType.Binary, entity.Photo ); database.AddInParameter(commandWrapper, "@Notes", DbType.String, entity.Notes ); database.AddInParameter(commandWrapper, "@ReportsTo", DbType.Int32, (entity.ReportsTo.HasValue ? (object) entity.ReportsTo : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@PhotoPath", DbType.String, entity.PhotoPath ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } //Stop Tracking Now that it has been updated and persisted. if (DataRepository.Provider.EnableEntityTracking) { EntityManager.StopTracking(entity.EntityTrackingKey); } entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Update an existing row in the datasource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Customers object to update.</param> /// <remarks> /// After updating the datasource, the Northwind.Entities.Customers object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Update(TransactionManager transactionManager, Northwind.Entities.Customers entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Customers_Update", _useStoredProcedure); database.AddInParameter(commandWrapper, "@CustomerId", DbType.StringFixedLength, entity.CustomerId ); database.AddInParameter(commandWrapper, "@OriginalCustomerId", DbType.StringFixedLength, entity.OriginalCustomerId); database.AddInParameter(commandWrapper, "@CompanyName", DbType.String, entity.CompanyName ); database.AddInParameter(commandWrapper, "@ContactName", DbType.String, entity.ContactName ); database.AddInParameter(commandWrapper, "@ContactTitle", DbType.String, entity.ContactTitle ); database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address ); database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City ); database.AddInParameter(commandWrapper, "@Region", DbType.String, entity.Region ); database.AddInParameter(commandWrapper, "@PostalCode", DbType.String, entity.PostalCode ); database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country ); database.AddInParameter(commandWrapper, "@Phone", DbType.String, entity.Phone ); database.AddInParameter(commandWrapper, "@Fax", DbType.String, entity.Fax ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } //Stop Tracking Now that it has been updated and persisted. if (DataRepository.Provider.EnableEntityTracking) { EntityManager.StopTracking(entity.EntityTrackingKey); } entity.OriginalCustomerId = entity.CustomerId; entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Inserts a Northwind.Entities.Suppliers object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Suppliers object to insert.</param> /// <remarks> /// After inserting into the datasource, the Northwind.Entities.Suppliers object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Insert(TransactionManager transactionManager, Northwind.Entities.Suppliers entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Suppliers_Insert", _useStoredProcedure); database.AddOutParameter(commandWrapper, "@SupplierId", DbType.Int32, 4); database.AddInParameter(commandWrapper, "@CompanyName", DbType.String, entity.CompanyName ); database.AddInParameter(commandWrapper, "@ContactName", DbType.String, entity.ContactName ); database.AddInParameter(commandWrapper, "@ContactTitle", DbType.String, entity.ContactTitle ); database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address ); database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City ); database.AddInParameter(commandWrapper, "@Region", DbType.String, entity.Region ); database.AddInParameter(commandWrapper, "@PostalCode", DbType.String, entity.PostalCode ); database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country ); database.AddInParameter(commandWrapper, "@Phone", DbType.String, entity.Phone ); database.AddInParameter(commandWrapper, "@Fax", DbType.String, entity.Fax ); database.AddInParameter(commandWrapper, "@HomePage", DbType.String, entity.HomePage ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } object _supplierId = database.GetParameterValue(commandWrapper, "@SupplierId"); entity.SupplierId = (System.Int32)_supplierId; entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Update an existing row in the datasource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Orders object to update.</param> /// <remarks> /// After updating the datasource, the Northwind.Entities.Orders object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Update(TransactionManager transactionManager, Northwind.Entities.Orders entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Orders_Update", _useStoredProcedure); database.AddInParameter(commandWrapper, "@OrderId", DbType.Int32, entity.OrderId ); database.AddInParameter(commandWrapper, "@CustomerId", DbType.StringFixedLength, entity.CustomerId ); database.AddInParameter(commandWrapper, "@EmployeeId", DbType.Int32, (entity.EmployeeId.HasValue ? (object) entity.EmployeeId : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@OrderDate", DbType.DateTime, (entity.OrderDate.HasValue ? (object) entity.OrderDate : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@RequiredDate", DbType.DateTime, (entity.RequiredDate.HasValue ? (object) entity.RequiredDate : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@ShippedDate", DbType.DateTime, (entity.ShippedDate.HasValue ? (object) entity.ShippedDate : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@ShipVia", DbType.Int32, (entity.ShipVia.HasValue ? (object) entity.ShipVia : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@Freight", DbType.Currency, (entity.Freight.HasValue ? (object) entity.Freight : System.DBNull.Value) ); database.AddInParameter(commandWrapper, "@ShipName", DbType.String, entity.ShipName ); database.AddInParameter(commandWrapper, "@ShipAddress", DbType.String, entity.ShipAddress ); database.AddInParameter(commandWrapper, "@ShipCity", DbType.String, entity.ShipCity ); database.AddInParameter(commandWrapper, "@ShipRegion", DbType.String, entity.ShipRegion ); database.AddInParameter(commandWrapper, "@ShipPostalCode", DbType.String, entity.ShipPostalCode ); database.AddInParameter(commandWrapper, "@ShipCountry", DbType.String, entity.ShipCountry ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } //Stop Tracking Now that it has been updated and persisted. if (DataRepository.Provider.EnableEntityTracking) { EntityManager.StopTracking(entity.EntityTrackingKey); } entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity)); return Convert.ToBoolean(results); }
/// <summary> /// Inserts a Northwind.Entities.Products object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Northwind.Entities.Products object to insert.</param> /// <remarks> /// After inserting into the datasource, the Northwind.Entities.Products object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Insert(TransactionManager transactionManager, Northwind.Entities.Products entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Products_Insert", _useStoredProcedure); database.AddOutParameter(commandWrapper, "@ProductId", DbType.Int32, 4); database.AddInParameter(commandWrapper, "@ProductName", DbType.String, entity.ProductName ); database.AddInParameter(commandWrapper, "@SupplierId", DbType.Int32, (entity.SupplierId.HasValue ? (object) entity.SupplierId : System.DBNull.Value)); database.AddInParameter(commandWrapper, "@CategoryId", DbType.Int32, (entity.CategoryId.HasValue ? (object) entity.CategoryId : System.DBNull.Value)); database.AddInParameter(commandWrapper, "@QuantityPerUnit", DbType.String, entity.QuantityPerUnit ); database.AddInParameter(commandWrapper, "@UnitPrice", DbType.Currency, (entity.UnitPrice.HasValue ? (object) entity.UnitPrice : System.DBNull.Value)); database.AddInParameter(commandWrapper, "@UnitsInStock", DbType.Int16, (entity.UnitsInStock.HasValue ? (object) entity.UnitsInStock : System.DBNull.Value)); database.AddInParameter(commandWrapper, "@UnitsOnOrder", DbType.Int16, (entity.UnitsOnOrder.HasValue ? (object) entity.UnitsOnOrder : System.DBNull.Value)); database.AddInParameter(commandWrapper, "@ReorderLevel", DbType.Int16, (entity.ReorderLevel.HasValue ? (object) entity.ReorderLevel : System.DBNull.Value)); database.AddInParameter(commandWrapper, "@Discontinued", DbType.Boolean, entity.Discontinued ); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database,commandWrapper); } object _productId = database.GetParameterValue(commandWrapper, "@ProductId"); entity.ProductId = (System.Int32)_productId; entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity)); return Convert.ToBoolean(results); }