多条件查询

 /// <summary>
        /// 根据输入的判断条件进行多项查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Search_Click(object sender, EventArgs e)
        {
            var result = from u in context.SRC_DEF_PLATFORM
                         select u;
            if (!String.IsNullOrEmpty(name.Text))
            {
                result = result.Where(p => p.PLATFORM_NAME.Contains(name.Text));
            }
            if (!String.IsNullOrEmpty(createName.Text))
            {
                result = result.Where(p => p.DEFINE_PERSON.Contains(createName.Text));
            }
            if (!String.IsNullOrEmpty(time.Text))
            {
                DateTime t = Convert.ToDateTime(time.Text);
                result = result.Where(p => p.DEFINE_TIME >= t);
            }
            if (!String.IsNullOrEmpty(time1.Text))
            {
                DateTime t = Convert.ToDateTime(time1.Text);
                result = result.Where(p => p.DEFINE_TIME <= t);
            }
            if (!String.IsNullOrEmpty(gzl1.Text.ToString()))
            {
                int duration1 = Convert.ToInt32(gzl1.Text);
                result = result.Where(p => p.WORKLOAD >= duration1);
            }
            if (!String.IsNullOrEmpty(gzl2.Text.ToString()))
            {
                int duration2 = Convert.ToInt32(gzl2.Text);
                result = result.Where(p => p.WORKLOAD <= duration2);
            }
            if (!String.IsNullOrEmpty(gq1.Text.ToString()))
            {
                int workload1 = Convert.ToInt32(gq1.Text);
                result = result.Where(p => p.DURATION >= workload1);
            }
            if (!String.IsNullOrEmpty(gq2.Text.ToString()))
            {
                int workload2 = Convert.ToInt32(gq2.Text);
                result = result.Where(p => p.DURATION <= workload2);
            }
            //ViewState["list"] = result;
            GetBing(result.ToList());
        }
原文地址:https://www.cnblogs.com/liuxinls/p/3075924.html