private static string alterTableCommandText(MetadataSqlSchema schema, List <string> existingColumns) { string cmd = null; var schemaColumns = schema.Columns; var columns = schemaColumns.Where(x => !existingColumns.Any(y => y == x.Name)); if (columns.Any()) { cmd = $"ALTER TABLE {schema.TableName} ADD "; int count = columns.Count(); int index = 0; foreach (var column in columns) { index += 1; cmd += $"{column.Name} {column.DbTypeName}"; if (column.IsAutoIncrementing) { cmd += $" Identity(1,1)"; } if (!column.AllowNulls) { cmd += $" NOT NULL"; } if (index < count) { cmd += ", "; } } } return(cmd); }
public static MetadataSqlSchema Map(MetadataSqlSchema schema) { foreach (var column in schema.Columns) { column.DbTypeName = column.ToDbTypeName(); } return(schema); }
private static List <SqlDataColumn> getIndexes(MetadataSqlSchema schema) { var indexes = schema.Columns.Where(x => x.IsIndex == true); if (indexes.Any()) { return(indexes.ToList()); } else { return(new List <SqlDataColumn>()); } }
private static List <SqlDataColumn> getIndexes(MetadataSqlSchema schema, List <string> existingColumns) { var schemaColumns = schema.Columns; var columns = schemaColumns.Where(x => !existingColumns.Any(y => y == x.Name)); if (columns.Any()) { return(columns.ToList()); } else { return(new List <SqlDataColumn>()); } }
private static string createTableCommandText(MetadataSqlSchema schema) { string cmd = $"CREATE TABLE {schema.TableName}( "; var columns = schema.Columns; foreach (var column in columns) { cmd += $"{column.Name} {column.DbTypeName}"; if (column.IsAutoIncrementing) { cmd += $" Identity(1,1)"; } if (!column.AllowNulls) { cmd += $" NOT NULL"; } cmd += ","; } string primaryKey = getPrimaryKeyText(schema); cmd += $" {primaryKey})"; return(cmd); }
private static string getPrimaryKeyText(MetadataSqlSchema schema) { string ids = "Id"; string cmd = $"CONSTRAINT PK_{schema.TableName} PRIMARY KEY"; var columns = schema.Columns.Where(x => x.IsPrimaryKey == true); if (columns.Any()) { int count = columns.Count(); int index = 0; ids = ""; foreach (var column in columns) { index += 1; ids += column.Name; if (index < count) { ids += ","; } } } cmd += $"({ids})"; return(cmd); }