private void UpdateAll(Plat_util_CodeBase entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPlat_util_CodeBase Plat_util_CodeBaseEntity = entity as PersistentPlat_util_CodeBase; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(Plat_util_CodeBaseDAO.SqlUpdate); db.AddInParameter(dbCommand, "@CodeBaseGuid", DbType.Guid, Plat_util_CodeBaseEntity.CodeBaseGuid); db.AddInParameter(dbCommand, "@CodeBaseCode", DbType.String, Plat_util_CodeBaseEntity.CodeBaseCode); db.AddInParameter(dbCommand, "@CodeBaseName", DbType.String, Plat_util_CodeBaseEntity.CodeBaseName); db.AddInParameter(dbCommand, "@CodeBaseType", DbType.String, Plat_util_CodeBaseEntity.CodeBaseType); db.AddInParameter(dbCommand, "@CodeBaseDesc", DbType.String, Plat_util_CodeBaseEntity.CodeBaseDesc); db.AddInParameter(dbCommand, "@OnModuleGuid", DbType.Guid, Plat_util_CodeBaseEntity.OnModuleGuid); db.AddInParameter(dbCommand, "@ParentCodeBaseGuid", DbType.Guid, Plat_util_CodeBaseEntity.ParentCodeBaseGuid); db.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, Plat_util_CodeBaseEntity.IsActive); db.AddInParameter(dbCommand, "@MyMark", DbType.Int32, Plat_util_CodeBaseEntity.MyMark); int result = db.ExecuteNonQuery(dbCommand, transaction); if (result == 0) { throw new EntityNotFoundException(); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } }
/// <summary> /// Insert /// </summary> public Plat_util_CodeBase Insert(Plat_util_CodeBase entity) { ArgumentValidator.CheckForNullArgument(entity, "entity"); PersistentPlat_util_CodeBase Plat_util_CodeBaseEntity = entity as PersistentPlat_util_CodeBase; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(Plat_util_CodeBaseDAO.SqlInsert); db.AddInParameter(dbCommand, "@CodeBaseGuid", DbType.Guid, Plat_util_CodeBaseEntity.CodeBaseGuid); db.AddInParameter(dbCommand, "@CodeBaseCode", DbType.String, Plat_util_CodeBaseEntity.CodeBaseCode); db.AddInParameter(dbCommand, "@CodeBaseName", DbType.String, Plat_util_CodeBaseEntity.CodeBaseName); db.AddInParameter(dbCommand, "@CodeBaseType", DbType.String, Plat_util_CodeBaseEntity.CodeBaseType); db.AddInParameter(dbCommand, "@CodeBaseDesc", DbType.String, Plat_util_CodeBaseEntity.CodeBaseDesc); db.AddInParameter(dbCommand, "@OnModuleGuid", DbType.Guid, Plat_util_CodeBaseEntity.OnModuleGuid); db.AddInParameter(dbCommand, "@ParentCodeBaseGuid", DbType.Guid, Plat_util_CodeBaseEntity.ParentCodeBaseGuid); db.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, Plat_util_CodeBaseEntity.IsActive); db.AddInParameter(dbCommand, "@MyMark", DbType.Int32, Plat_util_CodeBaseEntity.MyMark); int result = db.ExecuteNonQuery(dbCommand); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } return(Plat_util_CodeBaseEntity as Plat_util_CodeBase); }
private void UpdateSome(Plat_util_CodeBase entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPlat_util_CodeBase Plat_util_CodeBaseEntity = entity as PersistentPlat_util_CodeBase; StringBuilder sqlUpdateSome = new StringBuilder(); sqlUpdateSome.Append("UPDATE dbo.Plat_util_CodeBase SET "); PropertyInfo[] propertyInfos = Plat_util_CodeBaseEntity.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(Plat_util_CodeBaseEntity, null); ORProperty property = EntityMapping[propertyInfo.Name]; if (!property.IsPrimaryKey) { if (!Plat_util_CodeBaseEntity.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 CodeBaseGuid = @CodeBaseGuid "); 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); } }