Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Các trường hợp khoản hỗ trợ tất cả các bộ lọc các yếu tố điều kiện bạn mong chờ từ SQL, bao gồm cả các toán tử so sánh ( =, | 296 Microsoft ADO.NET 4 Step by Step Internally LINQ uses the Where extension method and a lambda expression that expresses the condition that filters the original collection. C var results transport.Where tr tr.SpeedClass 1 Visual Basic Dim results transport.Where Function tr tr.SpeedClass 1 The Where clause supports all the conditional filtering elements you would expect from SQL including the comparison operators and so on the logical operators And Or and Not in Visual Basic and in C and support for complex expressions. Add parentheses as needed to allow for conditional grouping of filters. C var results from tr in transport where tr.SpeedClass 1 tr.Name.EndsWith cycle select tr Visual Basic Dim results From tr In transport Where tr.SpeedClass 1 And tr.Name Like cycle Select tr Sorting Results with the Order By Clause The Order By clause sorts the projected and filtered results by one or more properties or expressions. Each sort field in the comma-separated list that follows the Order By keywords is processed from left to right. Optional Ascending the default and Descending modifiers appear after any of the sort fields. C var results from tr in transport orderby tr.SpeedClass descending tr.Name select tr Visual Basic Dim results From tr In transport Order By tr.SpeedClass Descending tr.Name Select tr Chapter 17 Introducing LINQ 297 LINQ uses the OrderBy or its OrderByDescending counterpart extension method to sort a projection on a field. When sorting on a single field that method does a great job but it always assumes that the records to be sorted have not been previously sorted. If you opt to develop a query using extension methods and try to string together multiple OrderBy methods the results will be sorted only by the last rightmost OrderBy call. C ---- This sorts by tr.Name ascending ONLY var results transport.OrderByDescending tr tr.SpeedClass .OrderBy tr tr.Name Visual Basic ----- This sorts by tr.Name ascending ONLY Dim results .