예제 #1
0
        public void OldMethod()
        {
            //请在页面加上参数id=1

            using (SqlSugarClient db = SugarDao.GetInstance())    //开启数据库连接
            {
                db.IsGetPageParas = true;                         //使用无参模式直接将Requst中的ID传给@id无需在代码中写出来
                var kvs  = SqlSugarTool.GetParameterDictionary(); //获取QqueryString和Form参数集合
                var list = db.Queryable <Student>();

                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    list = list.Where(it => it.id == Convert.ToInt32(kvs["name"]));
                }
                //if (!string.IsNullOrEmpty(Request["id"]))
                //{
                //    list = list.Where(it => it.Sex == Convert.ToInt32(kvs["Sex"]));
                //}
                //if (!string.IsNullOrEmpty(Request["id"]))
                //{
                //    list = list.Where(it => it.xxx == Convert.ToInt32(kvs["xxx"]));
                //}
                //if (!string.IsNullOrEmpty(Request["id"]))
                //{
                //    list = list = list.Where(it => it.xxxx == Convert.ToInt32(kvs["xxxxx"]));
                //}

                //获取页面所有参数到键值对
                //var kvs= SqlSugarTool.GetParameterDictionary();
            }
        }
예제 #2
0
        public void NewMethod()
        {
            //请在页面加上参数id=1

            using (SqlSugarClient db = SugarDao.GetInstance())        //开启数据库连接
            {
                db.IsGetPageParas = true;                             //使用无参模式直接将Requst中的ID传给@id无需在代码中写出来
                var kvs  = SqlSugarTool.GetParameterDictionary(true); //true不为空的所有参数
                var list = db.Queryable <Student>();
                foreach (var kv in kvs)
                {
                    list = list.Where(string.Format("{0}=@{0}", kv.Key));
                }
            }
        }
        internal void RequestParasToSqlParameters(SqlParameterCollection oldParas)
        {
            var oldParaList      = oldParas.Cast <SqlParameter>().ToList();
            var paraDictionarAll = SqlSugarTool.GetParameterDictionary();

            if (paraDictionarAll != null && paraDictionarAll.Count() > 0)
            {
                foreach (KeyValuePair <string, string> it in paraDictionarAll)
                {
                    var par = new SqlParameter("@" + it.Key, it.Value);
                    if (!oldParaList.Any(oldPara => oldPara.ParameterName == ("@" + it.Key)))
                    {
                        oldParas.Add(par);
                    }
                }
            }
        }