Exemplo n.º 1
0
        public static void ShowSalesByRegionAndPeriod(string shipRegion, DateTime startDate, DateTime endDate)
        {
            using (var db = new NorthwindDB.NorthwindEntities())
            {
                var orders = db.Orders
                             .Where(o => o.ShipRegion == shipRegion &&
                                    o.OrderDate >= startDate &&
                                    o.OrderDate <= endDate)
                             .Select(o => o.OrderID + " " + o.OrderDate + " " + o.ShipRegion);

                foreach (var order in orders)
                {
                    Console.WriteLine(order);
                }
            }
        }
Exemplo n.º 2
0
        public static void ShowCustomerByOrderDateAndShippingCountryNativeSql(int year, string country)
        {
            string query = String.Format(@"
                SELECT CONCAT(c.CompanyName, ' ', o.OrderDate, ' ', o.ShipCountry, o.OrderID)
                FROM dbo.Orders o
                    INNER JOIN dbo.Customers c
                    ON o.CustomerID = c.CustomerID
                WHERE YEAR(o.OrderDate) = {0} AND o.ShipCountry = '{1}'",
                                         year, country);

            using (var db = new NorthwindDB.NorthwindEntities())
            {
                var queryResult = db.Database.SqlQuery <string>(query).ToList();

                foreach (var foundResult in queryResult)
                {
                    Console.WriteLine(foundResult);
                }
            }
        }