.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending

时间:2022-10-18 21:14:14

介绍
    ·Select - Select选择;延迟
    ·Where - Where查询;延迟
    ·OrderBy - 按指定表达式对集合正序排序;延迟
    ·OrderByDescending - 按指定表达式对集合倒序排序;延迟
    ·GroupBy - 分组;延迟
    ·Join - Join查询;延迟
    ·GroupJoin - 分组Join查询;延迟
    ·以上查询操作符所对应的查询语法

示例
Summary.aspx.cs

.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Data;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Configuration;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Collections;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Linq;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Web;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Web.Security;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Web.UI;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Web.UI.WebControls;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Web.UI.WebControls.WebParts;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Web.UI.HtmlControls;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Xml.Linq;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing System.Collections.Generic;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingusing DAL;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescendingpublic partial class LINQ_Summary : System.Web.UI.Page
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending{
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        NorthwindDataContext _ctx = new NorthwindDataContext();
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        string[] _ary = null;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        protected void Page_Load(object sender, EventArgs e)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                _ary = new string[] { "asp.net", "csharp", "xhtml", "css", "javascript",    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        "wcf", "wpf", "silverlight", "linq", "wf",    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        "sqlserver", "asp.net ajax", "ssis", "ssas", "ssrs" };
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // Select - Select选择;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                Summary_Select();
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // Where - Where查询;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                Summary_Where();
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // OrderBy - 按指定表达式对集合正序排序;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // OrderByDescending - 按指定表达式对集合倒序排序;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                Summary_OrderBy_OrderByDescending();
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // GroupBy - 分组;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                Summary_GroupBy();
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // Join - Join查询;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                Summary_Join();
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // GroupJoin - 分组Join查询;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                Summary_GroupJoin();
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending}
 
Select - Select选择;延迟
/// <summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// Select - Select选择;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// </summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        void Summary_Select()
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 使用Select查询操作符
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var categories = _ctx.Categories.Select(
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        c => new { CategoryName = "类别名称:" + c.CategoryName });
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var c in categories)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += c.CategoryName + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 与上面的Select查询操作符相对应的查询语法
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var categories2 = from c in _ctx.Categories
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                                    select new { CategoryName = "类别名称:" + c.CategoryName };
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var c in categories2)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += c.CategoryName + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        }
 
运行结果
类别名称:Beverages
类别名称:Condiments
类别名称:Confections
类别名称:Dairy Products
类别名称:Grains/Cereals
类别名称:Meat/Poultry
类别名称:Produce
类别名称:Seafood
Where - Where查询;延迟
/// <summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// Where - Where查询;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// </summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        void Summary_Where()
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 使用Where查询操作符
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var ary = _ary.Where(a => a.StartsWith("w") && a.EndsWith("f"));
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (string s in ary)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += s + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 与上面的Where查询操作符相对应的查询语法
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var ary2 = from a in _ary
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                     where a.StartsWith("w") && a.EndsWith("f")
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                     select a;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (string s in ary2)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += s + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        }
 
运行结果
wcf
wpf
wf

OrderBy - 按指定表达式对集合正序排序;延迟
OrderByDescending - 按指定表达式对集合倒序排序;延迟

.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending /// <summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// OrderBy - 按指定表达式对集合正序排序;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// OrderByDescending - 按指定表达式对集合倒序排序;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// </summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        void Summary_OrderBy_OrderByDescending()
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 使用OrderBy查询操作符
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var ary = (from a in _ary
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                     select a).OrderBy(a => a.Length); // OrderByDescending与OrderBy用法相同
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (string s in ary)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += s + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 与上面的OrderBy查询操作符相对应的查询语法
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var ary2 = from a in _ary
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                     orderby a.Length ascending // orderby xxx descending与orderby xxx ascending用法相同
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                     select a;
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (string s in ary2)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += s + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        }
 
运行结果
wf
css
wcf
wpf
linq
ssis
ssas
ssrs
xhtml
csharp
asp.net
sqlserver
javascript
silverlight
asp.net ajax
GroupBy - 分组;延迟
/// <summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// GroupBy - 分组;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// </summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        void Summary_GroupBy()
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 使用GroupBy查询操作符
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var list = (from a in _ary
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                        select a).GroupBy(a => a.Length).Select(
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                                g => new { Group = g.Key, Member = g });
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var g in list)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += g.Group + "个字符:<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        foreach (string s in g.Member)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                result.InnerHtml += "--" + s + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 与上面的GroupBy查询操作符相对应的查询语法
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var list2 = from a in _ary
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                        group a by a.Length into g
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                        select new { Group = g.Key, Member = g };
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var g in list2)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += g.Group + "个字符:<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        foreach (string s in g.Member)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                result.InnerHtml += "--" + s + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        }
 
 
运行结果
7个字符:
--asp.net
6个字符:
--csharp
5个字符:
--xhtml
3个字符:
--css
--wcf
--wpf
10个字符:
--javascript
11个字符:
--silverlight
4个字符:
--linq
--ssis
--ssas
--ssrs
2个字符:
--wf
9个字符:
--sqlserver
12个字符:
--asp.net ajax

Join - Join查询;延迟

/// <summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// Join - Join查询;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// </summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        void Summary_Join()
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 使用Join查询操作符
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var products = _ctx.Products.Join(
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        _ctx.Categories,    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        p => p.CategoryID,    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        c => c.CategoryID,    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        (p, c) => new { c.CategoryName, p.ProductName }).Take(5);
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var p in products)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += p.CategoryName + " - " + p.ProductName + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 与上面的Join查询操作符相对应的查询语法
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var products2 = (from p in _ctx.Products
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                                 join c in _ctx.Categories
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                                 on p.CategoryID equals c.CategoryID
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                                 select new { c.CategoryName, p.ProductName }).Take(5);
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var p in products2)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += p.CategoryName + " - " + p.ProductName + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        }
 
运行结果
Beverages - Chai
Beverages - Chang
Condiments - Aniseed Syrup
Condiments - Chef Anton's Cajun Seasoning
Condiments - Chef Anton's Gumbo Mix

GroupJoin - 分组Join查询;延迟

.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending /// <summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// GroupJoin - 分组Join查询;延迟
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        /// </summary>
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        void Summary_GroupJoin()
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 使用GroupJoin查询操作符
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var products = _ctx.Categories.GroupJoin(
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        _ctx.Products,    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        c => c.CategoryID,    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        p => p.CategoryID,    
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        (p, g) => new { p.CategoryName, ProductCount = g.Count() });
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var g in products)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += g.CategoryName + ":" + g.ProductCount + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                // 与上面的GroupJoin查询操作符相对应的查询语法
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                var products2 = from c in _ctx.Categories
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                                join p in _ctx.Products on c.CategoryID equals p.CategoryID into g
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                                                select new { CategoryName = c.CategoryName, ProductCount = g.Count() };
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                foreach (var g in products2)
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                {
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                        result.InnerHtml += g.CategoryName + ":" + g.ProductCount + "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                }
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending                result.InnerHtml += "<br />";
.NET 3.5(5) - LINQ查询操作符之Select、Where、OrderBy、OrderByDescending        }
 
运行结果
Beverages:12
Condiments:12
Confections:13
Dairy Products:10
Grains/Cereals:7
Meat/Poultry:6
Produce:5
Seafood:12