dapper 参数不定时用这种方法动态参数

       string where = null;
            var p = new DynamicParameters();
            if (classId != null)
            {
                where = " and classId=:classId ";
                p.Add("classId", classId);
            }
            if (key != null)
            {
                where = " and (name like :key or description like :key) ";
                key = string.Format("%{0}%", key);
                p.Add("key", key);
            }
原文地址:https://www.cnblogs.com/ruidong/p/7379696.html