<video id="pn1t1"><em id="pn1t1"><th id="pn1t1"></th></em></video><p id="pn1t1"></p>

<listing id="pn1t1"><sub id="pn1t1"><th id="pn1t1"></th></sub></listing>

<p id="pn1t1"><track id="pn1t1"><em id="pn1t1"></em></track></p>
<em id="pn1t1"></em>

    <address id="pn1t1"></address>

    <progress id="pn1t1"></progress>

    主頁 > 知識庫 > 網絡編程 > ASP/.NET >

    asp.net Linq 實現分組查詢

    來源:中國IT實驗室 作者:佚名 發表于:2013-07-23 17:53  點擊:
    首先我們還是先建立一個person.cs類 public class person { public string name { get; set; } public int age { get; set; } public string sex { get; set; } } 接下來我們往這個person類添加數據: List plist1 = new List(); plist1.Add(new person { nam
    首先我們還是先建立一個person.cs類  public class person
      {
      public string name
      { get; set; }
      public int age
      { get; set; }
      public string sex
      { get; set; }
      }
      接下來我們往這個person類添加數據:
      List plist1 = new List();
      plist1.Add(new person { name = "cxx1", age = 24, sex = "男" });
      plist1.Add(new person { name = "www.baidu.com", age = 25, sex = "男" });
      plist1.Add(new person { name = "www.52mvc.com", age = 26, sex = "男" });
      List plist2 = new List();
      plist2.Add(new person { name = "cxx1", age = 24, sex = "男" });
      plist2.Add(new person { name = "cxx2", age = 28, sex = "男" });
      plist2.Add(new person { name = "cxx4", age = 27, sex = "男" });
      plist2.Add(new person { name = "cxx5", age = 28, sex = "男" });
      // asp.net
      var query = from person p in plist1
      join person per in plist2
      on p.name equals per.name
      select new
      {
      名稱=p.name,
      性別=p.sex,
      年齡=p.age
      };
      gd2.DataSource = query;
      gd2.DataBind();
      返回的結果是:
      備注:這個方法是要查找出 plist1 與 plist2 之中,name名稱有相同記錄的數據。
      接下來我們來看看sql中的左連接left join 在linq中如何實現
      還是先來創建兩個cs 類。
      ///
      /// 手機列表
      ///
      public class MobileStore
      {
      public string mobId
      { set; get; }
      public string mobName
      { set; get; }
      }

    有幫助
    (0)
    0%
    沒幫助
    (0)
    0%
    {转码词1},{转码词2},{转码词3},{转码词4}