public virtual OperationBuilder<AddColumnOperation> Column( [NotNull] string type, [CanBeNull] string name = null, bool nullable = false, [CanBeNull] object defaultValue = null, [CanBeNull] string defaultValueSql = null, [CanBeNull] string computedColumnSql = null) { Check.NotEmpty(type, nameof(type)); var operation = new AddColumnOperation { Schema = _createTableOperation.Schema, Table = _createTableOperation.Name, Name = name, Type = type, IsNullable = nullable, DefaultValue = defaultValue, DefaultValueSql = defaultValueSql, ComputedColumnSql = computedColumnSql }; _createTableOperation.Columns.Add(operation); return new OperationBuilder<AddColumnOperation>(operation); }
public void CreateTableOperation_with_annotations(bool autoincrement, string pkName) { var addIdColumn = new AddColumnOperation { Name = "Id", ClrType = typeof(long), ColumnType = "INTEGER", IsNullable = false }; if (autoincrement) { addIdColumn.AddAnnotation(SqliteAnnotationNames.Prefix + SqliteAnnotationNames.Autoincrement, true); } Generate( new CreateTableOperation { Name = "People", Columns = { addIdColumn, new AddColumnOperation { Name = "EmployerId", ClrType = typeof(int), ColumnType = "int", IsNullable = true }, new AddColumnOperation { Name = "SSN", ClrType = typeof(string), ColumnType = "char(11)", IsNullable = true } }, PrimaryKey = new AddPrimaryKeyOperation { Name = pkName, Columns = new[] { "Id" } }, UniqueConstraints = { new AddUniqueConstraintOperation { Columns = new[] { "SSN" } } }, ForeignKeys = { new AddForeignKeyOperation { Columns = new[] { "EmployerId" }, PrincipalTable = "Companies", PrincipalColumns = new[] { "Id" } } } }); Assert.Equal( "CREATE TABLE \"People\" (" + EOL + " \"Id\" INTEGER NOT NULL" + (pkName != null ? $" CONSTRAINT \"{pkName}\"" : "") + " PRIMARY KEY" + (autoincrement ? " AUTOINCREMENT," : ",") + EOL + " \"EmployerId\" int," + EOL + " \"SSN\" char(11)," + EOL + " UNIQUE (\"SSN\")," + EOL + " FOREIGN KEY (\"EmployerId\") REFERENCES \"Companies\" (\"Id\")" + EOL + ");" + EOL, Sql); }