public static void CreateNewTableSource(string tableName, string alias, string expected)
        {
            var name   = ObjectName.Parse(tableName);
            var source = new SqlQueryExpressionSource(name, alias);

            Assert.True(source.IsTable);
            Assert.False(source.IsQuery);
            Assert.Equal(!String.IsNullOrWhiteSpace(alias), source.IsAliased);
            Assert.Equal(expected, source.ToString());
        }
Beispiel #2
0
        public virtual SqlQueryExpressionSource VisitQuerySource(SqlQueryExpressionSource source)
        {
            if (source.IsTable)
            {
                return(new SqlQueryExpressionSource(source.TableName, source.Alias));
            }

            var query = source.Query;

            if (query != null)
            {
                query = (SqlQueryExpression)Visit(query);
            }

            return(new SqlQueryExpressionSource(query, source.Alias));
        }
Beispiel #3
0
        public void Source(SqlQueryExpressionSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (source.IsAliased &&
                aliases.Contains(source.Alias))
            {
                throw new ArgumentException($"Another source defined the alias {source.Alias} in this query expression");
            }

            if (source.IsAliased)
            {
                aliases.Add(source.Alias);
            }

            source.UniqueKey = NewSourceKey();
            sources.Add(source);
        }
        public static void CreateNewQuerySource()
        {
            var fromTable = ObjectName.Parse("table1");
            var query     = new SqlQueryExpression();

            query.AllItems = true;
            query.From.Table(fromTable);
            var source = new SqlQueryExpressionSource(query, "a");

            Assert.True(source.IsQuery);
            Assert.False(source.IsTable);
            Assert.True(source.IsAliased);
            Assert.Equal("a", source.Alias);
            Assert.True(source.Query.AllItems);

            var expected = new SqlStringBuilder();

            expected.AppendLine("(SELECT *");
            expected.Append("  FROM table1) AS a");

            Assert.Equal(expected.ToString(), source.ToString());
        }