internal static ColumnInfo FromSQL(Column column) { var columnInfo = new ColumnInfo(column.Name, column.TypeName) { IsNullable = column.is_nullable, IsMaxLength = column.max_length == -1, IsIdentity = column.is_identity, MaxLength = column.max_length, Scale = column.scale, Precision = column.precision, IsRowGuid = column.is_rowguidcol, IsComputed = column.is_computed, ComputedColumnDefinitionExpression = column.computed_column_definition, IsPersisted = column.is_persisted, }; columnInfo.FixColumnType(); // Special case: SQL storage size for unicode is 2x size switch (columnInfo.DataType) { case "nvarchar": case "nchar": case "ntext": columnInfo.MaxLength = columnInfo.MaxLength / 2; break; } if (column.is_user_defined) { columnInfo.MaxLength = null; columnInfo.Scale = null; columnInfo.Precision = null; } if (column.default_object_id > 0) { columnInfo.DefaultConstraintExpression = "DEFAULT " + column.default_definition; if (!column.default_is_system_named) { columnInfo.DefaultConstraintExpression = "CONSTRAINT " + column.default_name + " " + columnInfo.DefaultConstraintExpression; } } if (!string.IsNullOrEmpty(column.check_constraint_definition)) { columnInfo.CheckConstraintExpression = "CHECK " + column.check_constraint_definition; if (!column.check_constraint_is_system_named) { columnInfo.CheckConstraintExpression = "CONSTRAINT " + column.check_constraint_name + " " + columnInfo.CheckConstraintExpression; } } return columnInfo; }
public AddColumn(string objectIdentifier, ColumnInfo column) { ObjectIdentitifer = objectIdentifier; Column = column; }
internal static ColumnInfo FromEF6(EdmProperty property, string tableName) { var typeName = property.TypeName; var isMaxLen = false; // Special case: the EDM treats 'nvarchar(max)' as a type name, but SQL Server treats // it as a type 'nvarchar' and a type qualifier. const string maxSuffix = "(max)"; if (typeName.EndsWith(maxSuffix)) { typeName = typeName.Substring(0, typeName.Length - maxSuffix.Length); isMaxLen = true; } var columnInfo = new ColumnInfo(property.Name, typeName) { IsNullable = property.Nullable, IsMaxLength = isMaxLen, IsIdentity = property.IsStoreGeneratedIdentity && typeName != "uniqueidentifier", MaxLength = property.IsMaxLengthConstant ? null : property.MaxLength, Scale = property.IsScaleConstant ? null : property.Scale, Precision = property.IsMaxLengthConstant ? null : property.Precision, }; // Special case: EDM can say a uniqueidentifier is "identity", but it // really means that there is a default constraint on the table. if (property.IsStoreGeneratedIdentity && typeName == "uniqueidentifier") { columnInfo.IsIdentity = false; columnInfo.DefaultConstraintExpression = "CONSTRAINT DF_" + tableName + "_" + columnInfo.Name + " DEFAULT NEWID()"; } // Special case: EDM gives "time" a Precision value, but in SQL it's actually Scale if (typeName == "time") { columnInfo.Scale = columnInfo.Precision; columnInfo.Precision = null; } columnInfo.FixColumnType(); // TODO: detect "rowversion" data types return columnInfo; }
public AlterColumn(string objectIdentifier, ColumnInfo column, string note) { ObjectIdentitifer = objectIdentifier; Column = column; Note = note ?? ""; }