linq使用日记

//普通查询
var query = (from t in ServiceList
                                 where t.CreateUserID == ActionID.ToInt(0) 87 
                                 select t);


     var query = (from t in table.AsEnumerable()
                             where t.Field<string>("姓名") != null && !string.IsNullOrEmpty(t.Field<string>("姓名").ToString())
                             group t by t.Field<string>("姓名") into g
                             select g);


//对比一个集合
    var doublesArray = superior.Split(',');
                    if (doublesArray.Count() > 0)
                    {
                        var foos = from tq in ServiceList
                                   where doublesArray.Contains(tq.CreateUserID.ToString())
                                   orderby tq.CreateDate descending
                                   select tq;
                        return foos.Count().ToString();
                    }

//分组

     var query = (from t in table.AsEnumerable()
                             where t.Field<string>("姓名") != null && !string.IsNullOrEmpty(t.Field<string>("姓名").ToString())
                             group t by t.Field<string>("姓名") into g
                             select g);

//取值

  string name = row.FirstOrDefault().Field<string>("姓名");

          var query1 = (from k in table.AsEnumerable()
                                      where k.Field<string>("姓名") == row.FirstOrDefault().Field<string>("姓名")
                            .ToString()

//绑定

                var query = (from t in ds.Tables[0].AsEnumerable()
                             // where t.Field<string>("QuestionNo") == QuestionNo
                             select t).Skip((this.Pager.CurrentPageIndex - 1) * this.Pager.PageSize).Take(this.Pager.PageSize);
                DataTable boundTable = query.CopyToDataTable<DataRow>();
                RepeaterCommentList.DataSource = boundTable;
                RepeaterCommentList.DataBind();


    //jbox
        function ImgPhoto(Id) {
            var option = {
                id: 'ImgPhoto', top: '15px', buttons: { '确认选择': true,'取消': false }, showClose: true, persistent: true, buttonsFocus: 0, bottomText: '确认操作:', submit: function (v, h, f) {
                    alert(v);
                    if (v == 0) {
                        return true; // close the window
                    }
                }
            };
            $.jBox.open('iframe:ImgeDialog.aspx?Id=' + Id, "图片库", 695, 430, option);

        }

//多参数in查询
 int[] JobStatus_Arry = { (int)Enums.JobStatus.待上传, (int)Enums.JobStatus.上传中 };
 MdDatacubeofjobinfotask _MdDatacubeofjobinfotaskModel = _MdDatacubeofjobinfotaskBL.GetList("").Where<MdDatacubeofjobinfotask>(k => JobStatus_Arry.Contains(k.Status.Value)).OrderBy(x => x.DataChange_CreateTime).FirstOrDefault();

上一篇:行列互转_整理贴[转]


下一篇:lambda函数常见用法