public AddColumn(string tablename, Column column) { RequiresReprojectionOf = tablename; Tablename = tablename; Column = column; }
public DocumentTable(string name) : base(name) { IdColumn = new SystemColumn("Id", typeof(string), length: 1024, isPrimaryKey: true); Register(IdColumn); EtagColumn = new SystemColumn("Etag", typeof(Guid)); Register(EtagColumn); CreatedAtColumn = new SystemColumn("CreatedAt", typeof(DateTimeOffset)); Register(CreatedAtColumn); ModifiedAtColumn = new SystemColumn("ModifiedAt", typeof(DateTimeOffset)); Register(ModifiedAtColumn); DocumentColumn = new Column("Document", typeof(byte[])); Register(DocumentColumn); MetadataColumn = new Column("Metadata", typeof(byte[])); Register(MetadataColumn); DiscriminatorColumn = new Column("Discriminator", typeof(string), length: 1024); Register(DiscriminatorColumn); AwaitsReprojectionColumn = new Column("AwaitsReprojection", typeof(bool)); Register(AwaitsReprojectionColumn); VersionColumn = new Column("Version", typeof(int)); Register(VersionColumn); }
public static SqlColumn Convert(Column column) { if (!ForNetType(column.Type).Any()) throw new ArgumentException("Can only project .NET simple types, Guid, DateTime, DateTimeOffset, TimeSpan and byte[]."); return new SqlColumn(ForNetType(column.Type).First().DbType, GetLength(column)); }
protected bool Equals(Column other) { return Name == other.Name && Type == other.Type && Length == other.Length && Nullable == other.Nullable && IsPrimaryKey == other.IsPrimaryKey && Equals(DefaultValue, other.DefaultValue); }
protected SqlBuilder GetColumnSqlType(Column column, string defaultValuePostfix = "") { if (column.Type == null) throw new ArgumentException($"Column {column.Name} must have a type"); var sql = new SqlBuilder(); var sqlColumn = SqlTypeMap.Convert(column); sql.Append(new SqlParameter { DbType = sqlColumn.DbType }.SqlDbType.ToString()); sql.Append(sqlColumn.Length != null, "(" + sqlColumn.Length + ")"); sql.Append(column.Nullable, "NULL").Or("NOT NULL"); sql.Append(column.DefaultValue != null, "DEFAULT '{0}'", column.DefaultValue); sql.Append(column.IsPrimaryKey, " PRIMARY KEY"); return sql; }
static int? GetLength(Column column) { if (column.Length != null) return column.Length; if (column.Type == typeof (string)) return Int32.MaxValue; if (column.Type == typeof(Enum)) return 255; if (column.Type == typeof (byte[])) return Int32.MaxValue; return null; }
static string GetLength(Column column) { if (column.Length != null) return column.Length == -1 ? "MAX" : column.Length.ToString(); if (column.Type == typeof (string)) return "1024"; if (column.Type == typeof(Enum)) return "255"; if (column.Type == typeof (byte[])) return "MAX"; if (column.Type == typeof (decimal)) return "28, 14"; return null; }
public void ColumnGetsNullabilityFromType(Type columnType, bool isNullable) { var column = new Column("SomeColumn", columnType); column.Nullable.ShouldBe(isNullable); }
public void PrimaryKeyColumnCanNotBeNullable(Type columnType) { var column = new Column("SomeColumn", columnType, isPrimaryKey: true); column.Nullable.ShouldBe(false); }
public ChangeColumnType(string tableName, Column column) { Unsafe = true; TableName = tableName; Column = column; }
public ColumnAlreadRegisteredException(Table table, Column column) : base(string.Format("The table {0} already has a column named {1} and is not of the same type.", table.Name, column.Name)) {}
public void Register(Column column) { columns.Add(column.Name, column); }