public void ResolveExpression(ResolveExpress re, Expression exp)
        {
            ResolveExpress.MemberType type = ResolveExpress.MemberType.None;
            var expStr        = exp.ToString();
            var isNotBool     = !expStr.Contains("True") && !expStr.Contains("False");
            var isContainsNot = expStr.Contains("Not");

            if (isContainsNot && expStr.IsMatch(@" => Not\(.+?\)") && !expStr.Contains("Contains"))
            {
                this.SqlWhere = string.Format(" AND {0}=0 or {0} is null ", Regex.Match(expStr, @" => Not\(.+\.(.+?)\)").Groups[1].Value);
            }
            else if (isNotBool)
            {
                this.SqlWhere = string.Format(" AND {0} ", re.CreateSqlElements(exp, ref type));
            }
            else
            {
                var isTrue  = Regex.IsMatch(expStr, @"\=\> True$");
                var isFalse = Regex.IsMatch(expStr, @"\=\> False$");
                if (isFalse)
                {
                    this.SqlWhere = string.Format(" AND 1<>1 ");
                }
                else if (isTrue)
                {
                }
                else
                {
                    this.SqlWhere = string.Format(" AND {0} ", re.CreateSqlElements(exp, ref type));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 查询分页记录
        /// </summary>
        /// <param name="ExpWhere">lamda表达式</param>
        /// <param name="SqlOrderBy">取值排序字段,如:Id Asc,CreateTime Desc</param>
        /// <param name="RecordCount">数据记录总数</param>
        /// <param name="PageIndex">页码,默认1</param>
        /// <param name="PageSize">页大小,默认20</param>
        /// <param name="UseReadonlySource">是否实用只读数据源,true-是,false-否</param>
        /// <returns></returns>
        public static List <T> List(Expression <Func <T, bool> > ExpWhere, string SqlOrderBy, out long RecordCount, int PageIndex = 1, int PageSize = 20, bool UseReadonlySource = true)
        {
            ResolveExpress re = new Tool.ResolveExpress();

            re.ResolveExpression(re, ExpWhere);
            string SqlWhere = "1=1" + re.SqlWhere;

            object[] SqlParams = re.SqlParams.ToArray();
            return(List(SqlWhere, SqlOrderBy, out RecordCount, PageIndex, PageSize, UseReadonlySource, SqlParams));
        }
Beispiel #3
0
        /// <summary>
        /// 查询统计信息
        /// </summary>
        /// <param name="ExpWhere">lamda表达式</param>
        /// <param name="UseReadonlySource">是否实用只读数据源,true-是,false-否</param>
        /// <returns></returns>
        public static long Count(Expression <Func <T, bool> > ExpWhere, bool UseReadonlySource = true)
        {
            ResolveExpress re = new Tool.ResolveExpress();

            re.ResolveExpression(re, ExpWhere);
            string SqlWhere = "1=1" + re.SqlWhere;
            string SqlText  = SqlGenerator.SQLBUILDER_Count(DB.ORM_TabInfo, SqlWhere);

            object[]      SqlParams = re.SqlParams.ToArray();
            Data.DBHelper db        = new Data.DBHelper(DB.ORM_TabInfo.ORMConnectionMark, UseReadonlySource);
            object        CountObj  = db.ExecTextScalar(SqlText, SqlParams);

            if (CountObj != null && CountObj != DBNull.Value)
            {
                long CountVal = Convert.ToInt64(CountObj);
                return(CountVal);
            }
            else
            {
                return(-1);
            }
        }