Esempio n. 1
0
        public new string Visit(System.Linq.Expressions.Expression exp)
        {
            base.Visit(exp);
            var str = IEnumerableHelper.ToString(SqlList.Reverse());

            return(str.Length > 0 ? str : "*");
        }
Esempio n. 2
0
        /// <summary>
        ///     排序解析入口
        /// </summary>
        /// <param name="lstExp"></param>
        public virtual string Visit(Dictionary <System.Linq.Expressions.Expression, bool> lstExp)
        {
            if (lstExp == null)
            {
                return(null);
            }
            var lst = new List <string>();

            foreach (var keyValue in lstExp)
            {
                Visit(keyValue.Key);
                while (SqlList.Count > 0)
                {
                    lst.Add($"{SqlList.Pop()} {(keyValue.Value ? "ASC" : "DESC")}");
                }
                //SqlList.Push();
            }
            lst.Reverse();
            return(IEnumerableHelper.ToString(lst, ", "));
        }
Esempio n. 3
0
        /// <summary>
        ///     查询多条记录
        /// </summary>
        /// <param name="pageSize">每页显示数量</param>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="isDistinct">返回当前条件下非重复数据</param>
        public virtual ISqlParam ToList(int pageSize, int pageIndex, bool isDistinct = false)
        {
            // 不分页
            if (pageIndex == 1)
            {
                ToList(pageSize, isDistinct);
                return(this);
            }

            var strSelectSql   = SelectVisitor.Visit(ExpBuilder.ExpSelect);
            var strWhereSql    = WhereVisitor.Visit(ExpBuilder.ExpWhere);
            var strOrderBySql  = OrderByVisitor.Visit(ExpBuilder.ExpOrderBy);
            var strDistinctSql = isDistinct ? "Distinct " : string.Empty;

            Check.IsTure(string.IsNullOrWhiteSpace(strOrderBySql) && ExpBuilder.SetMap.PhysicsMap.PrimaryFields.Count == 0, "不指定排序字段时,需要设置主键ID");

            strOrderBySql = "ORDER BY " + (string.IsNullOrWhiteSpace(strOrderBySql) ? $"{IEnumerableHelper.ToString(ExpBuilder.SetMap.PhysicsMap.PrimaryFields.Select(o => o.Value.Name))} ASC" : strOrderBySql);
            var strOrderBySqlReverse = strOrderBySql.Replace(" DESC", " [倒序]").Replace("ASC", "DESC").Replace("[倒序]", "ASC");

            if (!string.IsNullOrWhiteSpace(strWhereSql))
            {
                strWhereSql = "WHERE " + strWhereSql;
            }

            Sql.Append(string.Format("SELECT {0}TOP {2} {1} FROM (SELECT TOP {3} * FROM {4} {5} {6}) a  {7}", strDistinctSql, strSelectSql, pageSize, pageSize * pageIndex, DbProvider.KeywordAegis(Name), strWhereSql, strOrderBySql, strOrderBySqlReverse));
            return(this);
        }
Esempio n. 4
0
 /// <summary>
 ///     将List转换成字符串
 /// </summary>
 /// <param name="lst">要拼接的LIST</param>
 /// <param name="sign">分隔符</param>
 public static string ToString(this IEnumerable lst, string sign = ",")
 {
     return(IEnumerableHelper.ToString(lst, sign));
 }
Esempio n. 5
0
 public new string Visit(Expression exp)
 {
     base.Visit(exp);
     return(IEnumerableHelper.ToString(SqlList.Reverse(), " AND "));
 }
Esempio n. 6
0
 /// <summary>
 /// 包含的数字值是否存在
 /// </summary>
 /// <param name="fieldName">字段名称</param>
 /// <param name="lstParamName">多个值</param>
 /// <param name="isNot">true:不存在</param>
 public virtual string In(string fieldName, List <string> lstParamName, bool isNot) => $"{fieldName} {(isNot ? "Not" : "")} IN ({IEnumerableHelper.ToString(lstParamName)})";
Esempio n. 7
0
        public override ISqlParam ToList(int pageSize, int pageIndex, bool isDistinct = false)
        {
            // 不分页
            if (pageIndex == 1)
            {
                ToList(pageSize, isDistinct);
                return(this);
            }

            var strSelectSql  = SelectVisitor.Visit(ExpBuilder.ExpSelect);
            var strWhereSql   = WhereVisitor.Visit(ExpBuilder.ExpWhere);
            var strOrderBySql = OrderByVisitor.Visit(ExpBuilder.ExpOrderBy);

            var strDistinctSql = isDistinct ? "Distinct" : string.Empty;

            if (!string.IsNullOrWhiteSpace(strWhereSql))
            {
                strWhereSql = "WHERE " + strWhereSql;
            }

            Check.IsTure(string.IsNullOrWhiteSpace(strOrderBySql) && (ExpBuilder.SetMap.PhysicsMap.PrimaryFields.Count == 0), "不指定排序字段时,需要设置主键ID");

            strOrderBySql = "ORDER BY " + (string.IsNullOrWhiteSpace(strOrderBySql) ? $"{IEnumerableHelper.ToString(ExpBuilder.SetMap.PhysicsMap.PrimaryFields.Select(o => o.Value.Name), ",")} ASC" : strOrderBySql);

            Sql.Append(string.Format("SELECT {1} FROM (SELECT {0} {1},ROW_NUMBER() OVER({2}) as Row FROM {3} {4}) a WHERE Row BETWEEN {5} AND {6}", strDistinctSql, strSelectSql, strOrderBySql, DbProvider.KeywordAegis(Name), strWhereSql, (pageIndex - 1) * pageSize + 1, pageIndex * pageSize));
            return(this);
        }