一.查询

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
posted on 2012-02-15 20:03  gzh4455  阅读(132)  评论(0编辑  收藏  举报