public void AlterColumn(string schemaName, string tableName, StoreProperty column) { // only computed FK columns require schema change if (column.Fk) { // computed column must be dropped and recreated DeleteColumn(schemaName, tableName, column.Name, column); AddColumn(schemaName, tableName, column); } }
private void GenerateColumnScript(StringBuilder sb, string tableName, StoreProperty c, string op) { var nullable = c.Nullable ? "?" : ""; var reference = ""; var type = c.Type; if (c.Fk) { reference = $" FK {c.ForeignKeys[0].DefinitionName}.{c.ForeignKeys[0].PropertyName}"; type = c.ForeignKeys[0].Type; } sb.AppendLine($"{op} COLUMN {tableName}.{c.Name} ({type}{nullable}{reference})"); }
public void AddColumn(string schemaName, string tableName, StoreProperty column) { // only computed FK columns require schema change if (column.Fk) { var type = column.ForeignKeys[0].Type; var colType = type == "int" ? "INT" : "uniqueidentifier"; var sql = $@" ALTER TABLE [{schemaName}].[{tableName}] ADD [{column.Name}] AS CAST(JSON_VALUE({DATA_COLUMN},'$.{column.Name}') AS {colType}); "; ExecuteNonQuery(sql); } }