Dapper+Mysql 使用LIKE模糊查詢寫法踩坑

LIKE '%@Title%' 會解析成'%'@Title'%' 這裏用拼接也是不行的'%'+@Title+'%' 只能用MySQL函數方法拼接
        public dynamic GetListByFilter(ArticleModel filter, PageInfo pageInfo)
        {
            string _where = " where 1=1";
            if (!string.IsNullOrEmpty(filter.Title))
            {
                //LIKE '%@Title%' 會解析成'%'@Title'%' 這裏用拼接也是不行的'%'+@Title+'%' 只能用MySQL函數方法拼接
                _where += " and Title LIKE CONCAT('%',@Title,'%')";
            }
            if (filter.Status != null)
            {
                _where += " and Status=@Status";
            }
            return GetListByFilter(filter, pageInfo, _where);
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章