1. <tbody id="qiaf6"></tbody>
    2. <menuitem id="qiaf6"><dfn id="qiaf6"><menu id="qiaf6"></menu></dfn></menuitem>

      <option id="qiaf6"><source id="qiaf6"></source></option>

      1. 
        

          1. <menuitem id="qiaf6"></menuitem>

            主页 > 知识库 > 网络编程 > 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%
            香港最快开奖现场直播