2 using System.Collections.Generic;
\r
6 using NUnit.Framework;
\r
10 // test ns Linq_101_Samples
\r
12 namespace Test_NUnit_MySql.Linq_101_Samples
\r
14 namespace Test_NUnit_OracleODP.Linq_101_Samples
\r
16 namespace Test_NUnit_Oracle.Linq_101_Samples
\r
18 namespace Test_NUnit_PostgreSql.Linq_101_Samples
\r
20 namespace Test_NUnit_Sqlite.Linq_101_Samples
\r
22 namespace Test_NUnit_Ingres.Linq_101_Samples
\r
23 #elif MSSQL && L2SQL
\r
24 namespace Test_NUnit_MsSql_Strict.Linq_101_Samples
\r
26 namespace Test_NUnit_MsSql.Linq_101_Samples
\r
28 namespace Test_NUnit_Firebird.Linq_101_Samples
\r
32 public class OrderBy : TestBase
\r
34 [Test(Description = "OrderBy - Simple. This sample uses orderby to sort Employees by hire date.")]
\r
35 public void LinqToSqlOrderBy01()
\r
37 Northwind db = CreateDB();
\r
39 var q = from e in db.Employees
\r
43 var list = q.ToList();
\r
44 Assert.IsTrue(list.Count > 0);
\r
47 [Test(Description = "OrderBy - With where. This sample uses where and orderby to sort Orders shipped to London by freight.")]
\r
48 public void LinqToSqlOrderBy02()
\r
50 Northwind db = CreateDB();
\r
52 var q = from o in db.Orders
\r
53 where o.ShipCity == "Marseille"
\r
57 var list = q.ToList();
\r
58 Assert.IsTrue(list.Count > 0);
\r
61 [Test(Description = "OrderByDescending. This sample uses orderby to sort Products by unit price from highest to lowest.")]
\r
62 public void LinqToSqlOrderBy03()
\r
64 Northwind db = CreateDB();
\r
66 var q = from p in db.Products
\r
67 orderby p.UnitPrice descending
\r
70 var list = q.ToList();
\r
71 Assert.IsTrue(list.Count > 0);
\r
74 [Test(Description = "ThenBy. This sample uses a compound orderby to sort Customers by city and then contact name.")]
\r
75 public void LinqToSqlOrderBy04()
\r
77 Northwind db = CreateDB();
\r
79 var q = from c in db.Customers
\r
80 orderby c.City, c.ContactName
\r
83 var list = q.ToList();
\r
84 Assert.IsTrue(list.Count > 0);
\r
87 [Test(Description = "ThenByDescending. This sample uses orderby to sort Orders from EmployeeID 1 by ship-to country, and then by freight from highest to lowest.")]
\r
88 public void LinqToSqlOrderBy05()
\r
90 Northwind db = CreateDB();
\r
92 var q = from o in db.Orders
\r
93 where o.EmployeeID == 1
\r
94 orderby o.ShipCountry, o.Freight descending
\r
97 var list = q.ToList();
\r
98 Assert.IsTrue(list.Count > 0);
\r
101 #if !DEBUG && (SQLITE || (MSSQL && !L2SQL))
\r
104 [Test(Description = "OrderBy - Group by. This sample uses Orderby, Max and Group by to find the Products that have the highest unit price in each category, and sorts the group by category id.")]
\r
105 public void LinqToSqlOrderBy06()
\r
107 Northwind db = CreateDB();
\r
109 var categories = from p in db.Products
\r
110 orderby p.CategoryID
\r
111 group p by p.CategoryID into Group
\r
115 MostExpensiveProducts =
\r
117 where p2.UnitPrice == Group.Max(p3 => p3.UnitPrice)
\r
121 var list = categories.ToList();
\r
122 Assert.IsTrue(list.Count > 0);
\r