/// <summary> /// Adds the existing row default value. If the column has a value for IsNullable, this will also /// call SetNullable to create the expression, and will then set the column IsNullable to false. /// </summary> public virtual void SetExistingRowsTo(object existingRowValue) { //TODO: validate that 'value' isn't set to null for non nullable columns. If set to //null, maybe just remove the expressions?.. not sure of best way to handle this. var column = _builder.Column; if (column.ModificationType == ColumnModificationType.Create) { //ensure an UpdateDataExpression is created and cached for this column ExistingRowsData exRowExpr; if (!_existingRowsDataByColumn.TryGetValue(column, out exRowExpr)) { exRowExpr = new ExistingRowsData(); _existingRowsDataByColumn.Add(column, exRowExpr); } if (exRowExpr.SetExistingRowsExpression == null) { exRowExpr.SetExistingRowsExpression = new UpdateDataExpression { TableName = _builder.TableName, SchemaName = _builder.SchemaName, IsAllRows = true }; _context.Expressions.Add(exRowExpr.SetExistingRowsExpression); //Call SetNullable, to ensure that not-null columns are correctly set to //not null after existing rows have data populated. SetNullable(column.IsNullable ?? true); } exRowExpr.SetExistingRowsExpression.Set = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(column.Name, existingRowValue) }; } }
/// <summary> /// Adds the existing row default value. If the column has a value for IsNullable, this will also /// call SetNullable to create the expression, and will then set the column IsNullable to false. /// </summary> public virtual void SetExistingRowsTo(object existingRowValue) { //TODO: validate that 'value' isn't set to null for non nullable columns. If set to //null, maybe just remove the expressions?.. not sure of best way to handle this. var column = _builder.Column; if (column.ModificationType == ColumnModificationType.Create) { //ensure an UpdateDataExpression is created and cached for this column ExistingRowsData exRowExpr; if (!_existingRowsDataByColumn.TryGetValue(column, out exRowExpr)) { exRowExpr = new ExistingRowsData(); _existingRowsDataByColumn.Add(column, exRowExpr); } if (exRowExpr.SetExistingRowsExpression == null) { exRowExpr.SetExistingRowsExpression = new UpdateDataExpression { TableName = _builder.TableName, SchemaName = _builder.SchemaName, IsAllRows = true, }; _context.Expressions.Add(exRowExpr.SetExistingRowsExpression); //Call SetNullable, to ensure that not-null columns are correctly set to //not null after existing rows have data populated. SetNullable(column.IsNullable ?? true); } exRowExpr.SetExistingRowsExpression.Set = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>(column.Name, existingRowValue) }; } }