/// <summary> /// Sets a value for a particular column in the record /// </summary> /// <param name="columnName">Name of the column, as defined in the database</param> /// <param name="oValue">The value to set the type to</param> public void SetColumnValue(string columnName, object oValue) { columnSettings = columnSettings ?? new TableSchema.TableColumnSettingCollection(); // add the column to the DirtyColumns // if this instance has already been loaded // and this is a change to existing values if (IsLoaded && !IsNew) { TableSchema.Table schema = GetSchema(); object oldValue = null; string oldValueMsg = "NULL"; string newValueMsg = "NULL"; bool areEqualOrBothNull = false; try { oldValue = columnSettings.GetValue(columnName); } catch {} if (oldValue == null && oValue == null) { areEqualOrBothNull = true; } else { if (oldValue != null) { oldValueMsg = oldValue.ToString(); areEqualOrBothNull = oldValue.Equals(oValue); } if (oValue != null) { newValueMsg = oValue.ToString(); } } TableSchema.TableColumn dirtyCol = schema.GetColumn(columnName); if (dirtyCol != null && !areEqualOrBothNull) { string auditMessage = String.Format("Value changed from {0} to {1}{2}", oldValueMsg, newValueMsg, Environment.NewLine); TableSchema.TableColumn dirtyEntry = DirtyColumns.GetColumn(columnName); if (dirtyEntry != null) { DirtyColumns.Remove(dirtyEntry); auditMessage = String.Concat(dirtyCol.AuditMessage, auditMessage); } dirtyCol.AuditMessage = auditMessage; DirtyColumns.Add(dirtyCol); } } columnSettings.SetValue(columnName, oValue); }
/// <summary> /// Sets the Primary Key of the object /// </summary> /// <param name="oValue">The o value.</param> protected virtual void SetPrimaryKey(object oValue) { columnSettings.SetValue(BaseSchema.PrimaryKey.ColumnName, oValue); }