zoukankan      html  css  js  c++  java
  • Linq的基本使用

    一.查询

    1.查找单一的记录,如果没有返回NULL

           XLInfo oXL = db.XLInfos.FirstOrDefault(p => p.XLDM == "100");

                 XLInfo xl = db.XLInfos.SingleOrDefault(p => p.XLDM == "10");
                if (xl != null)
                    this.TextBox1.Text = xl.XL;
                else
                    this.TextBox1.Text = "Null";
    2. 查找总记录条数或者记录存不存在

              int n = db.XLInfos.Count(q => q.XLDM == "100");
              this.TextBox1.Text = n.ToString();

    对于返回记录数多的,可以用LongCount()

        var q = db.Customers.LongCount();

    3. 一般查询,查询数据集

      var query = from q in db.XLInfos select new { q.XL, q.XLDM };

      var query = (from q in db.XLInfos select new { q.XL, q.XLDM }).ToList();

            public List<XLInfo> GetItems()
            {
                return db.XLInfos.ToList();
            }

    5. 一些函数,查询非重复数据

    var q = (from c in db.Customers
             select c.City )
            .Distinct();
    一些资料
    1. 函数
    http://www.cnblogs.com/lyj/archive/2008/01/23/1049686.html
  • 相关阅读:
    (原)学以致用:用数学公式'幂函数'支持生产经营分析
    CString 成员函数用法大全
    致hr新人的一封信
    [恢]hdu 2560
    [恢]hdu 1907
    [恢]hdu 1267
    [恢]hdu 2554
    [恢]hdu 1329
    [恢]hdu 2317
    [恢]hdu 2555
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2353130.html
Copyright © 2011-2022 走看看