Exemplo n.º 1
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));
        }
Exemplo n.º 2
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);
            }
        }