private void UpdateAll(PM_ALT_MESSAGE entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_MESSAGE PM_ALT_MESSAGEEntity = entity as PersistentPM_ALT_MESSAGE; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_MESSAGEDAO.SqlUpdate); db.AddInParameter(dbCommand, "@MsgPK", DbType.Int64, PM_ALT_MESSAGEEntity.MsgPK); db.AddInParameter(dbCommand, "@MsgSubject", DbType.String, PM_ALT_MESSAGEEntity.MsgSubject); db.AddInParameter(dbCommand, "@MsgContent", DbType.String, PM_ALT_MESSAGEEntity.MsgContent); db.AddInParameter(dbCommand, "@MsgType", DbType.Int32, PM_ALT_MESSAGEEntity.MsgType); db.AddInParameter(dbCommand, "@Format", DbType.String, PM_ALT_MESSAGEEntity.Format); db.AddInParameter(dbCommand, "@ObjectID", DbType.Guid, PM_ALT_MESSAGEEntity.ObjectID); db.AddInParameter(dbCommand, "@MsgFrom", DbType.String, PM_ALT_MESSAGEEntity.MsgFrom); db.AddInParameter(dbCommand, "@MsgTo", DbType.String, PM_ALT_MESSAGEEntity.MsgTo); db.AddInParameter(dbCommand, "@MsgCc", DbType.String, PM_ALT_MESSAGEEntity.MsgCc); db.AddInParameter(dbCommand, "@MsgBcc", DbType.String, PM_ALT_MESSAGEEntity.MsgBcc); db.AddInParameter(dbCommand, "@Attachments", DbType.String, PM_ALT_MESSAGEEntity.Attachments); db.AddInParameter(dbCommand, "@URL", DbType.String, PM_ALT_MESSAGEEntity.URL); db.AddInParameter(dbCommand, "@Category", DbType.String, PM_ALT_MESSAGEEntity.Category); db.AddInParameter(dbCommand, "@Source", DbType.String, PM_ALT_MESSAGEEntity.Source); db.AddInParameter(dbCommand, "@ErrorMsg", DbType.String, PM_ALT_MESSAGEEntity.ErrorMsg); db.AddInParameter(dbCommand, "@SentCnt", DbType.Int32, PM_ALT_MESSAGEEntity.SentCnt); db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_MESSAGEEntity.ModifiedOn); db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_MESSAGEEntity.RowDeleted); int result = db.ExecuteNonQuery(dbCommand, transaction); if (result == 0) { throw new EntityNotFoundException(); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } }
private void UpdateSome(PM_ALT_MESSAGE entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_MESSAGE PM_ALT_MESSAGEEntity = entity as PersistentPM_ALT_MESSAGE; StringBuilder sqlUpdateSome = new StringBuilder(); sqlUpdateSome.Append("UPDATE dbo.PM_ALT_MESSAGE SET "); PropertyInfo[] propertyInfos = PM_ALT_MESSAGEEntity.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_MESSAGEEntity, null); ORProperty property = EntityMapping[propertyInfo.Name]; if (!property.IsPrimaryKey) { if (!PM_ALT_MESSAGEEntity.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 MsgPK = @MsgPK "); 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); } }