Пример #1
0
        private void ManuallyInsertIgnoredItems(Catalog catalog)
        {
            var validatableSchemas = new List <Schema>();

            if (nodeToSchemaMap.Count > 0)
            {
                validatableSchemas.Add(catalog.Schemas[nodeToSchemaMap[MainNodeId]]);
                validatableSchemas.Add(catalog.Schemas[nodeToSchemaMap[AdditionalNodeId]]);
            }
            else
            {
                validatableSchemas.Add(catalog.DefaultSchema);
            }

            foreach (var schema in validatableSchemas)
            {
                using (var connection = driver.CreateConnection()) {
                    connection.Open();

                    var productTable     = schema.Tables["Product"];
                    var hiddenNameColumn = productTable.CreateColumn("HiddenName", GetTypeForString(255));
                    hiddenNameColumn.IsNullable = true;
                    var commandText = driver.Compile(SqlDdl.Alter(productTable, SqlDdl.AddColumn(hiddenNameColumn))).GetCommandText();
                    using (var command = connection.CreateCommand(commandText)) {
                        _ = command.ExecuteNonQuery();
                    }

                    var priceListTable      = schema.Tables["PriceList"];
                    var hiddenCommentColumn = priceListTable.CreateColumn("HiddenComment", GetTypeForString(255));
                    hiddenCommentColumn.IsNullable = true;
                    commandText = driver.Compile(SqlDdl.Alter(priceListTable, SqlDdl.AddColumn(hiddenCommentColumn))).GetCommandText();
                    using (var command = connection.CreateCommand(commandText)) {
                        _ = command.ExecuteNonQuery();
                    }

                    var currencyTable        = schema.Tables["Currency"];
                    var prefixColumnTemplate = "NotInDomain{0}";
                    var columns = new[] { "Column1", "Column2", "Column3" };
                    foreach (var column in columns)
                    {
                        var prefixColumn = currencyTable.CreateColumn(string.Format(prefixColumnTemplate, column), GetTypeForString(255));
                        prefixColumn.IsNullable = true;
                        commandText             = driver.Compile(SqlDdl.Alter(currencyTable, SqlDdl.AddColumn(prefixColumn))).GetCommandText();
                        using (var command = connection.CreateCommand(commandText)) {
                            _ = command.ExecuteNonQuery();
                        }
                    }

                    var ignoredTable = schema.CreateTable("HiddenTable");
                    var idColumn     = ignoredTable.CreateColumn("Id", GetTypeForInteger(SqlType.Int64));
                    idColumn.IsNullable = false;
                    var name = ignoredTable.CreateColumn("Name", GetTypeForString(255));
                    name.IsNullable = false;
                    var pk = ignoredTable.CreatePrimaryKey("PK_HiddenTable", idColumn);

                    using (var command = connection.CreateCommand(SqlDdl.Create(ignoredTable))) {
                        _ = command.ExecuteNonQuery();
                    }

                    var notInDomainTable1 = schema.CreateTable("NotInDomain1");
                    idColumn            = notInDomainTable1.CreateColumn("Id", GetTypeForInteger(SqlType.Int64));
                    idColumn.IsNullable = false;
                    name            = notInDomainTable1.CreateColumn("Name", GetTypeForString(255));
                    name.IsNullable = false;
                    pk = notInDomainTable1.CreatePrimaryKey("PK_NotInDomain1", idColumn);

                    using (var command = connection.CreateCommand(SqlDdl.Create(notInDomainTable1))) {
                        _ = command.ExecuteNonQuery();
                    }

                    var notInDomainTable2 = schema.CreateTable("NotInDomain2");
                    idColumn            = notInDomainTable2.CreateColumn("Id", GetTypeForInteger(SqlType.Int64));
                    idColumn.IsNullable = false;
                    name            = notInDomainTable2.CreateColumn("Name", GetTypeForString(255));
                    name.IsNullable = false;
                    pk = notInDomainTable2.CreatePrimaryKey("PK_NotInDomain2", idColumn);

                    using (var command = connection.CreateCommand(SqlDdl.Create(notInDomainTable2))) {
                        _ = command.ExecuteNonQuery();
                    }

                    var notInDomainTable3 = schema.CreateTable("NotInDomain3");
                    idColumn            = notInDomainTable3.CreateColumn("Id", GetTypeForInteger(SqlType.Int64));
                    idColumn.IsNullable = false;
                    name            = notInDomainTable3.CreateColumn("Name", GetTypeForString(255));
                    name.IsNullable = false;
                    pk = notInDomainTable3.CreatePrimaryKey("PK_NotInDomain3", idColumn);

                    using (var command = connection.CreateCommand(SqlDdl.Create(notInDomainTable3))) {
                        _ = command.ExecuteNonQuery();
                    }
                }
            }
        }