public static OperationBuilderSurface <CreateForeignKeyConstraintOperation> AddForeignKey(this IMigrationBuilder builder,
                                                                                                  string keyName,
                                                                                                  string dependentTable,
                                                                                                  IEnumerable <string> dependentColumns,
                                                                                                  string principalTable,
                                                                                                  IEnumerable <string> principalColumns,
                                                                                                  string dependentSchema  = null,
                                                                                                  string dependentCatalog = null,
                                                                                                  string principalCatalog = null,
                                                                                                  string principalSchema  = null,

                                                                                                  CascadeRule onUpdate = CascadeRule.None,
                                                                                                  CascadeRule onDelete = CascadeRule.None)
        {
            var op = new CreateForeignKeyConstraintOperation
            {
                Name           = new SubObjectName(dependentCatalog, dependentSchema, dependentTable, keyName),
                PrincipalTable = new ObjectName {
                    Catalog = principalCatalog ?? dependentCatalog, Schema = principalSchema ?? dependentSchema, Name = principalTable
                },

                OnDelete         = onDelete,
                OnUpdate         = onUpdate,
                DependentColumns = dependentColumns.Select(x => new ConstraintColumnDefinition {
                    Column = x
                }).ToList(),
                PrincipalColumns = principalColumns.Select(x => new ConstraintColumnDefinition {
                    Column = x
                }).ToList(),
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <CreateForeignKeyConstraintOperation>(op));
        }
Ejemplo n.º 2
0
        public static OperationBuilderSurface <AddColumnOperation> AddColumn <T>(this IMigrationBuilder builder,
                                                                                 string name, string table, string schema = null, string catalog = null,
                                                                                 string storeType     = null, bool?unicode = null, int?size = null, int?precision = null, bool nullable = false,
                                                                                 object defaultValue  = null, string defaultValueSql = null, string computedColumnExpression = null,
                                                                                 string collationName = null, DbType?explicitDbType  = null)
        {
            var op = new AddColumnOperation
            {
                Column = new ColumnDefinition
                {
                    Name = new SubObjectName {
                        Catalog = catalog, ParentName = table, Name = name, Schema = schema
                    },
                    Type                        = ColumnDefinition.InferType(explicitDbType, typeof(T), storeType, size, precision),
                    DefaultValue                = defaultValue,
                    IsNullable                  = nullable,
                    Unicode                     = unicode,
                    DefaultValueSql             = defaultValueSql,
                    ComputedColumnExpressionSql = computedColumnExpression,
                    CollationName               = null,
                }
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <AddColumnOperation>(op));
        }
        public static OperationBuilderSurface <CreateSchemaOperation> CreateSchema(this IMigrationBuilder builder, string schema, string catalog = null)
        {
            var op = new CreateSchemaOperation
            {
                Name = new ObjectName(catalog, schema, null)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <CreateSchemaOperation>(op));
        }
Ejemplo n.º 4
0
        public static OperationBuilderSurface <DropSequenceOperation> DropSequence(this IMigrationBuilder builder, string name, string schema = null, string catalog = null)
        {
            var op = new DropSequenceOperation
            {
                Name = new ObjectName(catalog, schema, name)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <DropSequenceOperation>(op));
        }
Ejemplo n.º 5
0
        public static OperationBuilderSurface <DropForeignKeyConstraintOperation> DropForeignKey(this IMigrationBuilder builder, string name, string table, string schema = null, string catalog = null)
        {
            var op = new DropForeignKeyConstraintOperation
            {
                Name = new SubObjectName(catalog, schema, table, name)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <DropForeignKeyConstraintOperation>(op));
        }
Ejemplo n.º 6
0
        public static OperationBuilderSurface <RenameColumnOperation> RenameColumn(this IMigrationBuilder builder, string oldName, string newName, string table, string schema = null, string catalog = null)
        {
            var op = new RenameColumnOperation
            {
                OldName = new SubObjectName(catalog, schema, table, oldName),
                NewName = new SubObjectName(catalog, schema, table, newName)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <RenameColumnOperation>(op));
        }
        public static OperationBuilderSurface <RenameTableOperation> RenameTable(this IMigrationBuilder builder, string oldName, string newName, string oldSchema = null, string newSchema = null, string catalog = null)
        {
            var op = new RenameTableOperation
            {
                OldName = new ObjectName(catalog, oldSchema, oldName),
                NewName = new ObjectName(catalog, newSchema, newName)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <RenameTableOperation>(op));
        }
        public static OperationBuilderSurface <CreatePrimaryKeyConstraintOperation> CreatePrimaryKey(
            IMigrationBuilder builder, string name, string table, IEnumerable <ConstraintColumnDefinition> columns,
            string schema = null, string catalog = null)
        {
            var op = new CreatePrimaryKeyConstraintOperation
            {
                Name    = new SubObjectName(catalog, schema, table, name),
                Columns = columns.ToList()
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <CreatePrimaryKeyConstraintOperation>(op));
        }
Ejemplo n.º 9
0
        public static OperationBuilderSurface <ExecuteSqlStatementOperation> ExecuteSqlStatement(this IMigrationBuilder builder, string sql, params SqlParameter[] sqlParameters)
        {
            var op = new ExecuteSqlStatementOperation
            {
                SqlStatement = new SqlStatement
                {
                    Sql        = sql,
                    Parameters = (sqlParameters ?? new SqlParameter[0]).ToList()
                }
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <ExecuteSqlStatementOperation>(op));
        }
Ejemplo n.º 10
0
        public static OperationBuilderSurface <CreateTableOperation> CreateTable <TColumns>(this IMigrationBuilder builder, string name,
                                                                                            Func <ColumnBuilder, TColumns> columns,
                                                                                            string schema  = null,
                                                                                            string catalog = null,
                                                                                            Action <CreateTableBuilder <TColumns> > constraints = null)
        {
            var op = new CreateTableOperation {
                Name = new ObjectName(catalog, schema, name)
            };
            var colInstance = columns(new ColumnBuilder());

            op.Columns = DecomposeColumns(colInstance, op.Name);
            builder.AddOperation(op);
            return(new OperationBuilderSurface <CreateTableOperation>(op));
        }
        public static OperationBuilderSurface <CreateSequenceOperation> CreateSequence(this IMigrationBuilder builder, string name, string schema = null, string catalog = null, DbType dbType = DbType.Int64, long?startValue = null, long?increment = null, long?minValue = null, long?maxValue = null, bool cycle = false, int?cache = null)
        {
            var op = new CreateSequenceOperation
            {
                Name      = new ObjectName(catalog, schema, name),
                Cycle     = cycle,
                StartWith = startValue,
                MaxValue  = maxValue,
                MinValue  = minValue,
                Increment = increment,
                DbType    = dbType,
                Cache     = cache
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <CreateSequenceOperation>(op));
        }
Ejemplo n.º 12
0
        public static OperationBuilderSurface <CreateIndexOperation> CreateIndex(this IMigrationBuilder builder,
                                                                                 string name, string table,
                                                                                 IEnumerable <IndexColumnDefinition> columns,
                                                                                 IEnumerable <IndexColumnDefinition> includes = null,
                                                                                 string schema = null, string catalog = null,
                                                                                 string filter = null)
        {
            var op = new CreateIndexOperation
            {
                Name     = new SubObjectName(catalog, schema, table, name),
                Columns  = columns.ToList(),
                Includes = (includes ?? new List <IndexColumnDefinition>()).ToList(),
                Filter   = filter,
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <CreateIndexOperation>(op));
        }