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 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());
        }