Exemplo n.º 1
0
        public void ComplexWhereClause()
        {
            #region expected

            string expectedQ1 =
                @"SELECT
                [dbo].[Blogs].[Id]
            FROM
                [dbo].[Blogs]
            WHERE
                (([dbo].[Blogs].[Id] > 2) OR ([dbo].[Blogs].[Name] = N'Ken'))
            ";

            #endregion

            var from = new FromClause(SQL.Blogs);
            var whereIdGraterThan2 = new WhereClause(SQL.Blogs.Id > 2);
            var whereIdNameIsKen = new WhereClause(SQL.Blogs.Name == "Ken");

            SQLQuery q1 = SQLQuery
                .Select(SQL.Blogs.Id)
                .From(from)
                .Where(whereIdGraterThan2 || whereIdNameIsKen);

            Assert.AreEqual(expectedQ1, q1.ToString());
        }
Exemplo n.º 2
0
        public void ToString_WithAlias_GeneratesCorrectSQLClause()
        {
            Tables_Blogs table = new Tables_Blogs().As("MyTable");

            var from = new FromClause(table);

            string expected =
                @"FROM
                [dbo].[Blogs] AS [MyTable]
            ";

            Assert.AreEqual(expected, from.ToString());
        }
Exemplo n.º 3
0
        public void ToString_Always_GeneratesCorrectSQLClause()
        {
            var table = new Tables_Blogs();

            var from = new FromClause(table);

            string expected =
                @"FROM
                [dbo].[Blogs]
            ";

            Assert.AreEqual(expected, from.ToString());
        }
Exemplo n.º 4
0
        public void ToString_WithJoin_GeneratesCorrectSQLClause()
        {
            var blogs = new Tables_Blogs();
            var posts = new Tables_Posts();

            FromClause from = new FromClause(blogs).Join(posts, blogs.Id == posts.BlogId);

            string expected =
                @"FROM
                [dbo].[Blogs]
            JOIN		[dbo].[Posts] ON
                    ([dbo].[Blogs].[Id] = [dbo].[Posts].[BlogId])
            ";

            Assert.AreEqual(expected, from.ToString());
        }
Exemplo n.º 5
0
        public void ReusingClauses()
        {
            #region expected

            string expectedQ1 =
                @"SELECT
                [dbo].[Blogs].[Id]
            FROM
                [dbo].[Blogs]
            WHERE
                ([dbo].[Blogs].[Id] = 2)
            ";
            string expectedQ2 =
                @"SELECT
                [dbo].[Blogs].[Name]
            FROM
                [dbo].[Blogs]
            WHERE
                ([dbo].[Blogs].[Id] = 2)
            ";

            #endregion

            var from = new FromClause(SQL.Blogs);
            var where = new WhereClause(SQL.Blogs.Id == 2);

            SQLQuery q1 = SQLQuery
                .Select(SQL.Blogs.Id)
                .From(from)
                .Where(where);

            SQLQuery q2 = SQLQuery
                .Select(SQL.Blogs.Name)
                .From(from)
                .Where(where);

            Assert.AreEqual(expectedQ1, q1.ToString());
            Assert.AreEqual(expectedQ2, q2.ToString());
        }