private void UpdateAll(PM_ALT_CONFIG_KEY entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_CONFIG_KEY PM_ALT_CONFIG_KEYEntity = entity as PersistentPM_ALT_CONFIG_KEY; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_CONFIG_KEYDAO.SqlUpdate); db.AddInParameter(dbCommand, "@ID", DbType.Int32, PM_ALT_CONFIG_KEYEntity.ID); db.AddInParameter(dbCommand, "@sOwner", DbType.String, PM_ALT_CONFIG_KEYEntity.sOwner); db.AddInParameter(dbCommand, "@sKey", DbType.String, PM_ALT_CONFIG_KEYEntity.sKey); db.AddInParameter(dbCommand, "@sValue", DbType.String, PM_ALT_CONFIG_KEYEntity.sValue); db.AddInParameter(dbCommand, "@sDescription", DbType.String, PM_ALT_CONFIG_KEYEntity.sDescription); int result = db.ExecuteNonQuery(dbCommand, transaction); if (result == 0) { throw new EntityNotFoundException(); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } }
/// <summary> /// Insert with transaction /// </summary> public PM_ALT_CONFIG_KEY Insert(PM_ALT_CONFIG_KEY entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_CONFIG_KEY PM_ALT_CONFIG_KEYEntity = entity as PersistentPM_ALT_CONFIG_KEY; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_CONFIG_KEYDAO.SqlInsert); db.AddInParameter(dbCommand, "@sOwner", DbType.String, PM_ALT_CONFIG_KEYEntity.sOwner); db.AddInParameter(dbCommand, "@sKey", DbType.String, PM_ALT_CONFIG_KEYEntity.sKey); db.AddInParameter(dbCommand, "@sValue", DbType.String, PM_ALT_CONFIG_KEYEntity.sValue); db.AddInParameter(dbCommand, "@sDescription", DbType.String, PM_ALT_CONFIG_KEYEntity.sDescription); int result = db.ExecuteNonQuery(dbCommand, transaction); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } return(PM_ALT_CONFIG_KEYEntity as PM_ALT_CONFIG_KEY); }
private void UpdateSome(PM_ALT_CONFIG_KEY entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_CONFIG_KEY PM_ALT_CONFIG_KEYEntity = entity as PersistentPM_ALT_CONFIG_KEY; StringBuilder sqlUpdateSome = new StringBuilder(); sqlUpdateSome.Append("UPDATE dbo.PM_ALT_CONFIG_KEY SET "); PropertyInfo[] propertyInfos = PM_ALT_CONFIG_KEYEntity.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_CONFIG_KEYEntity, null); ORProperty property = EntityMapping[propertyInfo.Name]; if (!property.IsPrimaryKey) { if (!PM_ALT_CONFIG_KEYEntity.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 ID = @ID "); 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); } }