Ejemplo n.º 1
0
 protected internal void DropColumn(string table, string name, string schema = "dbo", object anonymousArguments = null)
 {
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(name), null, "!string.IsNullOrWhiteSpace(name)");
     table = string.Format("{0}.{1}", schema, table);
     AddOperation(new DropColumnOperation(table, name, anonymousArguments));
 }
Ejemplo n.º 2
0
 protected internal void AddForeignKey(string dependentTable,
                                       string dependentColumn,
                                       string principalTable,
                                       string principalColumn    = null,
                                       bool cascadeDelete        = false,
                                       string name               = null,
                                       string schema             = "dbo",
                                       object anonymousArguments = null)
 {
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(dependentTable),
                                    null,
                                    "!string.IsNullOrWhiteSpace(dependentTable)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(dependentColumn),
                                    null,
                                    "!string.IsNullOrWhiteSpace(dependentColumn)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(principalTable),
                                    null,
                                    "!string.IsNullOrWhiteSpace(principalTable)");
     AddForeignKey(dependentTable,
                   new[]
     {
         dependentColumn
     },
                   principalTable,
                   (principalColumn != null)
             ? new[]
     {
         principalColumn
     }
             : null,
                   cascadeDelete,
                   name,
                   schema,
                   anonymousArguments);
 }
Ejemplo n.º 3
0
 protected internal void DropForeignKey(string dependentTable,
                                        string dependentColumn,
                                        string principalTable,
                                        string principalColumn    = null,
                                        string schema             = "dbo",
                                        object anonymousArguments = null)
 {
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(dependentTable),
                                    null,
                                    "!string.IsNullOrWhiteSpace(dependentTable)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(dependentColumn),
                                    null,
                                    "!string.IsNullOrWhiteSpace(dependentColumn)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(principalTable),
                                    null,
                                    "!string.IsNullOrWhiteSpace(principalTable)");
     DropForeignKey(dependentTable,
                    new[]
     {
         dependentColumn
     },
                    principalTable,
                    schema,
                    anonymousArguments);
 }
Ejemplo n.º 4
0
        protected internal void CreateProcedure <TParameters>(string name, string bodySql,
                                                              Func <ParameterBuilder, TParameters> parametersAction, string schema = "dbo", object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(name), null, "!string.IsNullOrWhiteSpace(name)");
            RuntimeFailureMethods.Requires(parametersAction != null, null, "parametersAction != null");
            name = string.Format("{0}.{1}", schema, name);
            var createOperation = new CreateProcedureOperation(name, bodySql, anonymousArguments);

            AddOperation(createOperation);
            var parameters = parametersAction(new ParameterBuilder());

            parameters.GetType().GetProperties().Each(delegate(PropertyInfo p, int i)
            {
                var parameterModel = p.GetValue(parameters, null) as ParameterModel;
                if (parameterModel != null)
                {
                    if (string.IsNullOrWhiteSpace(parameterModel.Name))
                    {
                        parameterModel.Name = p.Name;
                    }
                    createOperation.Parameters.Add(parameterModel);
                }
            }
                                                      );
        }
Ejemplo n.º 5
0
        protected internal TableBuilder <TColumns> CreateTable <TColumns>(string name,
                                                                          Func <ColumnBuilder, TColumns> columnsAction, string schema = "dbo",
                                                                          object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(name), null, "!string.IsNullOrWhiteSpace(name)");
            RuntimeFailureMethods.Requires(columnsAction != null, null, "columnsAction != null");
            name = string.Format("{0}.{1}", schema, name);
            var createTableOperation = new CreateTableOperation(name, anonymousArguments);

            AddOperation(createTableOperation);
            var columns = columnsAction(new ColumnBuilder());

            columns.GetType().GetProperties().Each(delegate(PropertyInfo p, int i)
            {
                var columnModel = p.GetValue(columns, null) as ColumnModel;
                if (columnModel != null)
                {
                    if (string.IsNullOrWhiteSpace(columnModel.Name))
                    {
                        columnModel.Name = p.Name;
                    }
                    createTableOperation.Columns.Add(columnModel);
                }
            }
                                                   );
            return(new TableBuilder <TColumns>(createTableOperation, this));
        }
Ejemplo n.º 6
0
 protected internal void Sql(string sql, bool suppressTransaction = false, object anonymousArguments = null)
 {
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(sql), null, "!string.IsNullOrWhiteSpace(sql)");
     AddOperation(new SqlOperation(sql, anonymousArguments)
     {
         SuppressTransaction = suppressTransaction
     });
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     Не надо это спользовать!!
 ///     RenameTable: удваивает название схемы в названии таблицы - жесть
 ///     Пример: dbo.table1 -> dbo.dbo.table2
 /// </summary>
 /// <param name="name"></param>
 /// <param name="newName"></param>
 /// <param name="schema"></param>
 /// <param name="anonymousArguments"></param>
 protected internal void RenameTable(string name, string newName, string schema = "dbo", object anonymousArguments = null)
 {
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(name), null, "!string.IsNullOrWhiteSpace(name)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(newName),
                                    null,
                                    "!string.IsNullOrWhiteSpace(newName)");
     name    = string.Format("{0}.{1}", schema, name);
     newName = string.Format("{0}.{1}", schema, newName);
     AddOperation(new RenameTableOperation(name, newName, anonymousArguments));
 }
Ejemplo n.º 8
0
        protected internal void DropPrimaryKey(string table, string schema = "dbo", object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
            table = string.Format("{0}.{1}", schema, table);
            var migrationOperation = new DropPrimaryKeyOperation(anonymousArguments)
            {
                Table = table
            };

            AddOperation(migrationOperation);
        }
Ejemplo n.º 9
0
        protected internal void DropIndex(string table, string[] columns, string schema = "dbo", object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
            RuntimeFailureMethods.Requires(columns != null, null, "columns != null");
            table = string.Format("{0}.{1}", schema, table);
            var dropIndexOperation = new DropIndexOperation(anonymousArguments)
            {
                Table = table
            };

            columns.Each(c => dropIndexOperation.Columns.Add(c)
                         );
            AddOperation(dropIndexOperation);
        }
Ejemplo n.º 10
0
        protected internal void DropForeignKey(string dependentTable, string name, string schema = "dbo", object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(dependentTable),
                                           null,
                                           "!string.IsNullOrWhiteSpace(dependentTable)");
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(name), null, "!string.IsNullOrWhiteSpace(name)");
            dependentTable = string.Format("{0}.{1}", schema, dependentTable);
            var migrationOperation = new DropForeignKeyOperation(anonymousArguments)
            {
                DependentTable = dependentTable,
                Name           = name
            };

            AddOperation(migrationOperation);
        }
Ejemplo n.º 11
0
        protected internal void AddColumn(string table,
                                          string name,
                                          Func <ColumnBuilder, ColumnModel> columnAction,
                                          string schema             = "dbo",
                                          object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(name), null, "!string.IsNullOrWhiteSpace(name)");
            RuntimeFailureMethods.Requires(columnAction != null, null, "columnAction != null");
            var columnModel = columnAction(new ColumnBuilder());

            columnModel.Name = name;
            table            = string.Format("{0}.{1}", schema, table);
            AddOperation(new AddColumnOperation(table, columnModel, anonymousArguments));
        }
Ejemplo n.º 12
0
        public TableBuilder <TColumns> PrimaryKey(Expression <Func <TColumns, object> > keyExpression, string name = null, object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(keyExpression != null, null, "keyExpression != null");
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation(anonymousArguments)
            {
                Name = name
            };

            (
                keyExpression.GetPropertyAccessList().Select(p => p.First().Name)).Each(delegate(string c)
            {
                addPrimaryKeyOperation.Columns.Add(c);
            }
                                                                                        );
            this._createTableOperation.PrimaryKey = addPrimaryKeyOperation;
            return(this);
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     Добавление таблицы для подсчета изменений
        /// </summary>
        protected internal void AddChangeSetTable(string table, string versionTable, string[] columns)
        {
            RuntimeFailureMethods.Requires(columns != null, null, "columns != null");

            if (_changeSets4Add.ContainsKey(table))
            {
                _changeSets4Add[table] = new ChangeSetModel {
                    Keys = columns, Table = table, VersionTable = versionTable
                }
            }
            ;
            else
            {
                _changeSets4Add.Add(table, new ChangeSetModel {
                    Keys = columns, Table = table, VersionTable = versionTable
                });
            }
        }
Ejemplo n.º 14
0
        public TableBuilder <TColumns> Index(Expression <Func <TColumns, object> > indexExpression, bool unique = false, object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(indexExpression != null, null, "indexExpression != null");
            var createIndexOperation = new CreateIndexOperation(anonymousArguments)
            {
                Table    = this._createTableOperation.Name,
                IsUnique = unique
            };

            (
                indexExpression.GetPropertyAccessList().Select(p => p.First().Name)).Each(delegate(string c)
            {
                createIndexOperation.Columns.Add(c);
            }
                                                                                          );
            this._migration.AddOperation(createIndexOperation);
            return(this);
        }
Ejemplo n.º 15
0
 protected internal void AddPrimaryKey(string table,
                                       string column,
                                       string name               = null,
                                       string schema             = "dbo",
                                       object anonymousArguments = null)
 {
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(column),
                                    null,
                                    "!string.IsNullOrWhiteSpace(column)");
     AddPrimaryKey(table,
                   new[]
     {
         column
     },
                   name,
                   schema,
                   anonymousArguments);
 }
Ejemplo n.º 16
0
 protected internal void CreateIndex(string table,
                                     string column,
                                     bool unique               = false,
                                     string name               = null,
                                     string schema             = "dbo",
                                     object anonymousArguments = null)
 {
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
     RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(column),
                                    null,
                                    "!string.IsNullOrWhiteSpace(column)");
     CreateIndex(table,
                 new[]
     {
         column
     },
                 unique,
                 name,
                 schema,
                 anonymousArguments);
 }
Ejemplo n.º 17
0
        protected internal void AddPrimaryKey(string table,
                                              string[] columns,
                                              string name               = null,
                                              string schema             = "dbo",
                                              object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
            RuntimeFailureMethods.Requires(columns != null, null, "columns != null");
            RuntimeFailureMethods.Requires(columns.Any(), null, "columns.Any()");
            table = string.Format("{0}.{1}", schema, table);
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation(anonymousArguments)
            {
                Table = table,
                Name  = name
            };

            columns.Each(c => addPrimaryKeyOperation.Columns.Add(c)
                         );

            AddOperation(addPrimaryKeyOperation);
        }
Ejemplo n.º 18
0
        protected internal void CreateIndex(string table,
                                            string[] columns,
                                            bool unique               = false,
                                            string name               = null,
                                            string schema             = "dbo",
                                            object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(table), null, "!string.IsNullOrWhiteSpace(table)");
            RuntimeFailureMethods.Requires(columns != null, null, "columns != null");
            RuntimeFailureMethods.Requires(columns.Any(), null, "columns.Any()");
            table = string.Format("{0}.{1}", schema, table);
            var createIndexOperation = new CreateIndexOperation(anonymousArguments)
            {
                Table    = table,
                IsUnique = unique,
                Name     = name
            };

            columns.Each(c => createIndexOperation.Columns.Add(c)
                         );
            AddOperation(createIndexOperation);
        }
Ejemplo n.º 19
0
        protected internal void DropForeignKey(string dependentTable,
                                               string[] dependentColumns,
                                               string principalTable,
                                               string schema             = "dbo",
                                               object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(dependentTable),
                                           null,
                                           "!string.IsNullOrWhiteSpace(dependentTable)");
            RuntimeFailureMethods.Requires(dependentColumns != null, null, "dependentColumns != null");
            RuntimeFailureMethods.Requires(dependentColumns.Any(), null, "dependentColumns.Any()");
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(principalTable),
                                           null,
                                           "!string.IsNullOrWhiteSpace(principalTable)");
            dependentTable = string.Format("{0}.{1}", schema, dependentTable);
            var dropForeignKeyOperation = new DropForeignKeyOperation(anonymousArguments)
            {
                DependentTable = dependentTable,
                PrincipalTable = principalTable
            };

            dependentColumns.Each(delegate(string c) { dropForeignKeyOperation.DependentColumns.Add(c); }
                                  );
            AddOperation(dropForeignKeyOperation);

            principalTable = string.Format("{0}.{1}", schema, principalTable);

            var dropForeignKeyOperation1 = new DropForeignKeyOperation(anonymousArguments)
            {
                DependentTable = dependentTable,
                PrincipalTable = principalTable
            };

            dependentColumns.Each(delegate(string c) { dropForeignKeyOperation1.DependentColumns.Add(c); });

            AddOperation(dropForeignKeyOperation1);
        }
Ejemplo n.º 20
0
        public TableBuilder <TColumns> ForeignKey(string principalTable, IEnumerable <string> principalColumns, Expression <Func <TColumns, object> > dependentKeyExpression, bool cascadeDelete = false, string name = null,
                                                  object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(principalTable), null, "!string.IsNullOrWhiteSpace(principalTable)");
            RuntimeFailureMethods.Requires(dependentKeyExpression != null, null, "dependentKeyExpression != null");
            var addForeignKeyOperation = new AddForeignKeyOperation(anonymousArguments)
            {
                Name           = name,
                PrincipalTable = principalTable,
                DependentTable = this._createTableOperation.Name,
                CascadeDelete  = cascadeDelete
            };

            if (principalColumns != null)
            {
                principalColumns.Each(addForeignKeyOperation.PrincipalColumns.Add);
            }
            (
                dependentKeyExpression.GetPropertyAccessList().Select(p => p.First().Name)).Each(
                c => addForeignKeyOperation.DependentColumns.Add(c)
                );
            this._migration.AddOperation(addForeignKeyOperation);
            return(this);
        }
Ejemplo n.º 21
0
        protected internal void AddForeignKey(string dependentTable,
                                              string[] dependentColumns,
                                              string principalTable,
                                              string[] principalColumns = null,
                                              bool cascadeDelete        = false,
                                              string name               = null,
                                              string schema             = "dbo",
                                              object anonymousArguments = null)
        {
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(dependentTable),
                                           null,
                                           "!string.IsNullOrWhiteSpace(dependentTable)");
            RuntimeFailureMethods.Requires(dependentColumns != null, null, "dependentColumns != null");
            RuntimeFailureMethods.Requires(dependentColumns.Any(), null, "dependentColumns.Any()");
            RuntimeFailureMethods.Requires(!string.IsNullOrWhiteSpace(principalTable),
                                           null,
                                           "!string.IsNullOrWhiteSpace(principalTable)");
            dependentTable = string.Format("{0}.{1}", schema, dependentTable);
            principalTable = string.Format("{0}.{1}", schema, principalTable);
            var addForeignKeyOperation = new AddForeignKeyOperation(anonymousArguments)
            {
                DependentTable = dependentTable,
                PrincipalTable = principalTable,
                CascadeDelete  = cascadeDelete,
                Name           = name
            };

            dependentColumns.Each(c => addForeignKeyOperation.DependentColumns.Add(c)
                                  );
            if (principalColumns != null)
            {
                principalColumns.Each(c => addForeignKeyOperation.PrincipalColumns.Add(c)
                                      );
            }
            AddOperation(addForeignKeyOperation);
        }
Ejemplo n.º 22
0
 public TableBuilder(CreateTableOperation createTableOperation, DbMigration migration)
 {
     RuntimeFailureMethods.Requires(createTableOperation != null, null, "createTableOperation != null");
     this._createTableOperation = createTableOperation;
     this._migration            = migration;
 }