Example #1
0
        public void SQLWithOrderByWithoutFrom()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).OrderBy(c.Country)
                ,
                @"SELECT CustomerId FROM Customers ORDER BY Country;"
                );
        }
Example #2
0
        public void SelectFromSelect_1()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.Country).From(Select(Distinct(c.Country)).From(c))
                ,
                @"SELECT Country AS DistinctCountries FROM (SELECT DISTINCT Country FROM Customers) x"
                );
        }
Example #3
0
        public void BasicSelectStatement_from_is_not_required()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID, c.CompanyName)
                ,
                "select customerid,companyName from customers"
                );
        }
Example #4
0
        public void SQLWithNot()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).Where(Not(c.Country.IsEqualTo("Germany")))
                ,
                @"SELECT CustomerId FROM Customers WHERE NOT Country='Germany'"
                );
        }
Example #5
0
        public void SQLWithDistinct()
        {
            var c = new Models.Customers();

            Verify(
                Select(Distinct(c.Country)).From(c)
                ,
                "SELECT DISTINCT Country FROM Customers"
                );
        }
Example #6
0
        public void SQLWithNotIn()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).Where(c.Country.IsNotIn("Germany", "France", "UK"))
                ,
                @"SELECT CustomerID FROM Customers WHERE Country NOT IN ('Germany', 'France', 'UK');"
                );
        }
Example #7
0
        public void SQLWith()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID)
                ,
                @"SELECT CustomerId FROM Customers "
                );
        }
Example #8
0
        public void SQLWithCountDistinct()
        {
            var c = new Models.Customers();

            Verify(
                Select(Count(Distinct(c.Country))).From(c)
                ,
                @"SELECT COUNT(DISTINCT Country) FROM Customers;
"
                );
        }
Example #9
0
        public void BasicSelectStatement()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID, c.CompanyName)
                .From(c)
                ,
                "select customerid,companyName from customers"
                );
        }
Example #10
0
        public void SQLWithLike()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).From(c).
                Where(Like(c.CompanyName, "%or%"))
                ,
                @"SELECT customerid FROM Customers
                  WHERE companyname LIKE '%or%'"
                );
        }
Example #11
0
        public void SQLWithOrderByAsc()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).From(c).
                Where(c.Country.IsEqualTo("Germany")).OrderBy(c.CustomerID)
                ,
                @"SELECT CustomerID FROM Customers
                  WHERE Country='Germany' order by CustomerID asc"
                );
        }
Example #12
0
        public void SQLWithOr()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).From(c).
                Where(c.City.IsEqualTo("Berlin").Or(c.City.IsEqualTo("München")))
                ,
                @"SELECT CustomerID FROM Customers
                  WHERE City='Berlin' OR City='München' "
                );
        }
Example #13
0
        public void SQLWithOrderByDescAsc()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).From(c).
                Where(c.Country.IsEqualTo("Germany")).OrderBy(c.Country, c.CompanyName, SortDirection.Descending)
                ,
                @"SELECT CustomerID FROM Customers
                  WHERE Country='Germany' order by Country ASC, CompanyName DESC"
                );
        }
Example #14
0
        public void SQLWithGroupByWithoutWhere()
        {
            var c = new Models.Customers();

            Verify(
                Select(Count(c.CustomerID), c.Country).GroupBy(c.Country)
                ,
                @"SELECT COUNT(CustomerID), Country
                 FROM Customers
                 GROUP BY Country;"
                );
        }
Example #15
0
        public void SQLWithAnd()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CustomerID).From(c).
                Where(c.Country.IsEqualTo("Germany").And(c.City.IsEqualTo("Berlin")))
                ,
                @"SELECT CustomerID FROM Customers
                  WHERE Country = 'Germany' AND City = 'Berlin'; "
                );
        }
Example #16
0
        public void TestListOfSelectItems()
        {
            var c       = new Models.Customers();
            var columns = new SelectItems {
                c.CustomerID, c.CompanyName
            };

            Verify(
                Select(columns, c.Phone)
                ,
                "select customerid,companyName,phone from customers"
                );
        }
Example #17
0
        public void SQLWithIsNotNull()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CompanyName, c.ContactName, c.Address).From(c).
                Where(c.Address.IsDifferentFrom((Text)null))
                ,
                @"SELECT CompanyName, ContactName, Address
                  FROM Customers
                    WHERE Address IS NOT NULL"
                );
        }
Example #18
0
        public void SQLWithGroupBy()
        {
            var c = new Models.Customers();

            Verify(
                Select(Count(c.CustomerID), c.Country).Where(Like(c.CompanyName, "%an%")).GroupBy(c.Country)
                ,
                @"SELECT COUNT(CustomerID), Country
                 FROM Customers
                 WHERE CompanyName LIKE '%an%'
                 GROUP BY Country;"
                );
        }
Example #19
0
        public void SQLWithLikeUsingUserDbMethods()
        {
            var c  = new Models.Customers();
            var db = new ENV.Data.UserDbMethods(() => c);

            Verify(
                Select(c.CustomerID).From(c).
                Where(db.Like(c.CompanyName, "*or*"))
                ,
                @"SELECT customerid FROM Customers
                  WHERE companyname LIKE '%or%'"
                );
        }
Example #20
0
        public void SQLWithUnionAll()
        {
            var o = new Models.Orders();
            var c = new Models.Customers();

            Verify(
                Select(c.City, c.Country).Where(c.Country.IsEqualTo("Germany")).UnionAll(
                    Select(o.ShipCity, o.ShipCountry).Where(o.ShipCountry.IsEqualTo("Germany"))).OrderBy(c.City)
                ,
                @"SELECT City, Country FROM Customers WHERE Country='Germany'
                  UNION  ALL
                  SELECT ShipCity, ShipCountry FROM orders WHERE ShipCountry='Germany'
                  ORDER BY City;"
                );
        }
Example #21
0
        public void SQLWithInnerJoins()
        {
            var o = new Models.Orders();
            var c = new Models.Customers();

            Verify(
                Select(o.OrderID, c.CompanyName, o.OrderDate).
                From(o).
                InnerJoin(c, o.CustomerID.IsEqualTo(c.CustomerID))
                ,
                @"SELECT  Orders.OrderID, Customers.CompanyName, Orders.OrderDate
                  FROM Orders
                  INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID "
                );
        }
Example #22
0
        public void SQLWithHavingCount()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.City)
                .GroupBy(c.City)
                .Having(new SqlPart(Count(), " = ", 1))

                ,
                @"select city
                from customers
                group by city
                having count(*)=1"
                );
        }
Example #23
0
        public void SQLWithLamda_1()
        {
            var u = new ENV.UserMethods();
            var o = new Models.Orders();
            var c = new Models.Customers();

            Verify(
                Select(o.OrderID, c.CompanyName, o.OrderDate).
                From(o).
                InnerJoin(c, new SqlPart(o.CustomerID, "=", new SqlFunction("Left", c.CustomerID, 5)))
                ,
                @"SELECT  Orders.OrderID, Customers.CompanyName, Orders.OrderDate
                  FROM Orders
                  INNER JOIN Customers ON Orders.CustomerID = left(Customers.CustomerID,5) "
                );
        }
Example #24
0
        public void SQLWithHaving()
        {
            var c = new Models.Customers();

            Verify(
                Select(Count(c.CustomerID), c.Country)
                .GroupBy(c.Country)
                .Having(new SqlPart(Count(c.CustomerID), " > ", 5))

                ,
                @"SELECT COUNT(CustomerID), Country
                FROM Customers
                GROUP BY Country
                HAVING COUNT(CustomerID) > 5"
                );
        }
Example #25
0
        public void SQLWithHavingOrderBy()
        {
            var c = new Models.Customers();

            Verify(
                Select(Count(c.CustomerID), c.Country)
                .GroupBy(c.Country)
                .Having(new SqlPart(Count(c.CustomerID), " > ", 5))
                .OrderBy(Count(c.CustomerID), SortDirection.Descending)
                ,
                @"SELECT COUNT(CustomerID), Country
                FROM Customers
                GROUP BY Country
                HAVING COUNT(CustomerID) > 5
				 ORDER BY COUNT(CustomerID) DESC"
                );
        }
Example #26
0
        public void SQLWithUnion()
        {
            var o = new Models.Orders();
            var c = new Models.Customers();

            Verify(
                Select(c.City, c.Country).Where(c.Country.IsEqualTo("Germany")).Union(

                    Select(o.ShipCity, o.ShipCountry).Where(o.ShipCountry.IsEqualTo("Germany"))).OrderBy(1, SortDirection.Descending)

                ,
                @"SELECT City, Country FROM Customers WHERE Country='Germany'
                  UNION 
                  SELECT ShipCity, ShipCountry FROM orders WHERE ShipCountry='Germany'
                  ORDER BY City desc;"
                );
        }
Example #27
0
        public void SQLWithRightJoin()
        {
            var o = new Models.Orders();
            var c = new Models.Customers();

            Verify(
                Select(c.CompanyName, o.OrderID).
                From(c).
                RightOuterJoin(o, o.CustomerID.IsEqualTo(c.CustomerID)).
                OrderBy(c.CompanyName)
                ,
                @"SELECT Customers.CompanyName, Orders.OrderID
                  FROM Customers
                  RIGHT JOIN Orders ON Customers.CustomerID=Orders.CustomerID
                  ORDER BY Customers.CompanyName "
                );
        }
Example #28
0
        public void SQLWithFullJoin()
        {
            var o = new Models.Orders();
            var c = new Models.Customers();

            Verify(
                Select(c.CompanyName, o.OrderID).
                From(c).
                FullOuterJoin(o, c.CustomerID.IsEqualTo(o.CustomerID)).
                OrderBy(c.CompanyName)
                ,
                @"SELECT Customers.CompanyName, Orders.OrderID
                  FROM Customers
                  FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
                  ORDER BY Customers.CompanyName "
                );
        }
Example #29
0
        public void SQLWithCase2()
        {
            var c = new Models.Customers();

            Verify(
                Select(c.CompanyName,
                       c.City, c.Country).OrderBy(
                    Case(c.City.IsNull(), c.Country).Else(c.City)
                    )
                ,
                @"SELECT CompanyName, City, Country
                FROM Customers
                ORDER BY
                (CASE
                    WHEN City IS NULL THEN Country
                    ELSE City
                END)"
                );
        }
Example #30
0
 public void AddCustomer(Customers customer)
 {
     context.Customers.Add(customer);
     context.SaveChanges();
 }