zoukankan      html  css  js  c++  java
  • linq的常用写法

    1.DataTable

            DataTable dt = udb.GetAllUser();
            DataTable dt1 = new DataTable();

            IEnumerable<DataRow> q1 = from r in dt.AsEnumerable()

                                      where r.Field<int>("车间ID") == Convert.ToInt32(车间ID) && r.Field<int>("IsAdmin") == 0
                                      orderby r.Field<int>("车间ID") ascending
                                      select r;
            dt1 = q1.CopyToDataTable();

    r.Field<int>("车间ID") 这么写也行Convert.ToInt32(r["车间ID"])

    2.List

                    List<DIC_RELA_RAILLINE_NODE> SelectGet =
                    (from x in DIC_RELA_RAILLINE_NODEs
                     where x.SUB_LINE_ID == RailTrackLines[i].R_ID.ToString()
                     orderby x.Center_kilo ascending
                     select x).ToList();

    3.对象关联

            var result = from x in SUIs

               from y in SUs

                         where x.JobNumber != y.JobNumber && y.DispatchID == "1"

               select new {

                   Name = x.Name,

                   Title = x.Name,

                   Body = x.Name,

               };

    或者

            List<Sale_UserInterface> result =
                (from x in SUIs
                 from y in SUs
                 where x.JobNumber != y.JobNumber && y.DispatchID == "1"
                 select x).ToList();

    分页的写法


            IEnumerable<DataRow> q1 = (from r in dt.AsEnumerable()

                                      orderby r.Field<int>("ID") ascending
                                       select r).Skip(startIndex - 1).Take(pageSize);

    Skip和Take

    用var

    var q1 = (from r in CUs                  

    orderby r.CreateTime ascending                  

    select r).Skip(startIndex - 1).Take(pageSize);

    List<Common_User> CUs2 = new List<Common_User>();         CUs2 = q1.ToList();

            var query = from l in 色彩s
    group l by new { l.色彩ID } into g
    select new
    {

    色彩ID = g.Key.色彩ID,
    Score = g.Sum(o => o.Score)
    };
    double q = db.MenuInfo.Where(p => p.PID == PID).Max(p => p.IOrder);



     

  • 相关阅读:
    查询是哪个进程占用了特定端口
    (面向c#开发人员) 编写javascript的好习惯一 false 值
    onerror 事件 如何使用 onerror 事件捕获网页中的错误。(chrome、opera、safari 浏览器不支持)
    查找url里面的flag元素判断操作
    jquery 弹出窗
    向上滚动
    kissy helpcenter
    kissyAPI
    IE6 动态创建 iframe 无法显示的 bug 芒果
    图片轮换动画仿GIF
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/2116295.html
Copyright © 2011-2022 走看看