private void UpdateAll(PM_ALT_LOG entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_LOG PM_ALT_LOGEntity = entity as PersistentPM_ALT_LOG; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_LOGDAO.SqlUpdate); db.AddInParameter(dbCommand, "@LogPK", DbType.Int64, PM_ALT_LOGEntity.LogPK); db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_LOGEntity.AlertID); db.AddInParameter(dbCommand, "@LogTitle", DbType.String, PM_ALT_LOGEntity.LogTitle); db.AddInParameter(dbCommand, "@LogContent", DbType.String, PM_ALT_LOGEntity.LogContent); db.AddInParameter(dbCommand, "@NotifiedCnt", DbType.Int32, PM_ALT_LOGEntity.NotifiedCnt); db.AddInParameter(dbCommand, "@IsClosed", DbType.Boolean, PM_ALT_LOGEntity.IsClosed); db.AddInParameter(dbCommand, "@RespondedBy", DbType.String, PM_ALT_LOGEntity.RespondedBy); db.AddInParameter(dbCommand, "@RespondedOn", DbType.DateTime, PM_ALT_LOGEntity.RespondedOn); db.AddInParameter(dbCommand, "@ResponseAction", DbType.String, PM_ALT_LOGEntity.ResponseAction); db.AddInParameter(dbCommand, "@ResponseCause", DbType.String, PM_ALT_LOGEntity.ResponseCause); db.AddInParameter(dbCommand, "@ResponseNotes", DbType.String, PM_ALT_LOGEntity.ResponseNotes); db.AddInParameter(dbCommand, "@AuditedBy", DbType.String, PM_ALT_LOGEntity.AuditedBy); db.AddInParameter(dbCommand, "@AuditedOn", DbType.DateTime, PM_ALT_LOGEntity.AuditedOn); db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_LOGEntity.RowDeleted); db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_LOGEntity.CreatedBy); db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_LOGEntity.CreatedOn); db.AddInParameter(dbCommand, "@NotifiedBy", DbType.String, PM_ALT_LOGEntity.NotifiedBy); db.AddInParameter(dbCommand, "@NotifiedOn", DbType.DateTime, PM_ALT_LOGEntity.NotifiedOn); int result = db.ExecuteNonQuery(dbCommand, transaction); if (result == 0) { throw new EntityNotFoundException(); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } }
/// <summary> /// Insert /// </summary> public PM_ALT_LOG Insert(PM_ALT_LOG entity) { ArgumentValidator.CheckForNullArgument(entity, "entity"); PersistentPM_ALT_LOG PM_ALT_LOGEntity = entity as PersistentPM_ALT_LOG; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_LOGDAO.SqlInsert); db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_LOGEntity.AlertID); db.AddInParameter(dbCommand, "@LogTitle", DbType.String, PM_ALT_LOGEntity.LogTitle); db.AddInParameter(dbCommand, "@LogContent", DbType.String, PM_ALT_LOGEntity.LogContent); db.AddInParameter(dbCommand, "@NotifiedCnt", DbType.Int32, PM_ALT_LOGEntity.NotifiedCnt); db.AddInParameter(dbCommand, "@IsClosed", DbType.Boolean, PM_ALT_LOGEntity.IsClosed); db.AddInParameter(dbCommand, "@RespondedBy", DbType.String, PM_ALT_LOGEntity.RespondedBy); db.AddInParameter(dbCommand, "@RespondedOn", DbType.DateTime, PM_ALT_LOGEntity.RespondedOn); db.AddInParameter(dbCommand, "@ResponseAction", DbType.String, PM_ALT_LOGEntity.ResponseAction); db.AddInParameter(dbCommand, "@ResponseCause", DbType.String, PM_ALT_LOGEntity.ResponseCause); db.AddInParameter(dbCommand, "@ResponseNotes", DbType.String, PM_ALT_LOGEntity.ResponseNotes); db.AddInParameter(dbCommand, "@AuditedBy", DbType.String, PM_ALT_LOGEntity.AuditedBy); db.AddInParameter(dbCommand, "@AuditedOn", DbType.DateTime, PM_ALT_LOGEntity.AuditedOn); db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_LOGEntity.RowDeleted); db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_LOGEntity.CreatedBy); db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_LOGEntity.CreatedOn); db.AddInParameter(dbCommand, "@NotifiedBy", DbType.String, PM_ALT_LOGEntity.NotifiedBy); db.AddInParameter(dbCommand, "@NotifiedOn", DbType.DateTime, PM_ALT_LOGEntity.NotifiedOn); int result = db.ExecuteNonQuery(dbCommand); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } return(PM_ALT_LOGEntity as PM_ALT_LOG); }
private void UpdateSome(PM_ALT_LOG entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_LOG PM_ALT_LOGEntity = entity as PersistentPM_ALT_LOG; StringBuilder sqlUpdateSome = new StringBuilder(); sqlUpdateSome.Append("UPDATE dbo.PM_ALT_LOG SET "); PropertyInfo[] propertyInfos = PM_ALT_LOGEntity.GetType().GetProperties(); Hashtable propertyValues = new System.Collections.Hashtable(); int columnCountForUpdate = 0; foreach (PropertyInfo propertyInfo in propertyInfos) { if (EntityMapping.ContainsProperty(propertyInfo.Name)) { object propertyValue = propertyInfo.GetValue(PM_ALT_LOGEntity, null); ORProperty property = EntityMapping[propertyInfo.Name]; if (!property.IsPrimaryKey) { if (!PM_ALT_LOGEntity.IsDefaultValue(propertyInfo.Name)) { propertyValues[propertyInfo.Name] = propertyValue; sqlUpdateSome.Append(" " + property.ColumnName + " = @" + property.ColumnName + ","); columnCountForUpdate++; } } else { propertyValues[propertyInfo.Name] = propertyValue; } } } if (columnCountForUpdate == 0) { return; } sqlUpdateSome.Remove(sqlUpdateSome.Length - 1, 1); sqlUpdateSome.Append(" WHERE 1 = 1 "); sqlUpdateSome.Append(" AND LogPK = @LogPK "); try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(sqlUpdateSome.ToString()); foreach (DictionaryEntry de in propertyValues) { ORProperty property = EntityMapping[de.Key.ToString()]; db.AddInParameter(dbCommand, "@" + property.ColumnName, property.DatabaseType, de.Value); } int result = db.ExecuteNonQuery(dbCommand, transaction); if (result == 0) { throw new EntityNotFoundException(); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } }