public void GetAllTables_IndirectTables()
        {
            var tableDefinition3    = TableDefinitionObjectMother.Create(_storageProviderDefinition);
            var baseUnionDefinition = new UnionViewDefinition(
                _storageProviderDefinition,
                new EntityNameDefinition(null, "UnionView"),
                new IRdbmsStorageEntityDefinition[] { _unionViewDefinition, tableDefinition3 },
                _objectIDProperty,
                _timestampProperty,
                new SimpleStoragePropertyDefinition[0],
                new IIndexDefinition[0],
                new EntityNameDefinition[0]);

            var result = baseUnionDefinition.GetAllTables().ToArray();

            Assert.That(result, Is.EqualTo(new[] { _tableDefinition1, _tableDefinition2, tableDefinition3 }));
        }
Example #2
0
        public override IDbCommand Create(IRdbmsProviderCommandExecutionContext commandExecutionContext)
        {
            ArgumentUtility.CheckNotNull("commandExecutionContext", commandExecutionContext);

            var command = commandExecutionContext.CreateDbCommand();

            var fullProjection = _orderedColumns.UnionWithSelectedColumns(_selectedColumns);

            var  statement = new StringBuilder();
            bool first     = true;

            _comparedColumns.AddParameters(command, SqlDialect);

            foreach (var table in _unionViewDefinition.GetAllTables())
            {
                if (!first)
                {
                    statement.Append(" UNION ALL ");
                }

                var adjustedProjection = fullProjection.AdjustForTable(table);
                AppendSelectClause(statement, adjustedProjection);
                AppendFromClause(statement, table);

                statement.Append(" WHERE ");
                _comparedColumns.AppendComparisons(statement, command, SqlDialect);

                first = false;
            }

            AppendOrderByClause(statement, _orderedColumns);

            statement.Append(SqlDialect.StatementDelimiter);

            command.CommandText = statement.ToString();

            return(command);
        }
        public void GetAllTables()
        {
            var result = _unionViewDefinition.GetAllTables().ToArray();

            Assert.That(result, Is.EqualTo(new[] { _tableDefinition1, _tableDefinition2 }));
        }