Exemplo n.º 1
0
        /// <summary>
        /// 获取数据表总项数
        /// </summary>
        /// <param name="expression">linq表达式 谓词</param>
        /// <returns></returns>
        public long GetCount(Expression <Func <TEntity, bool> > expression = null)
        {
            try
            {
                if (_Conn.State == ConnectionState.Closed)
                {
                    _Conn.Open();
                }
                var predicate = DapperLinqBuilder <TEntity> .FromExpression(expression);

                return(_Conn.Count <TEntity>(predicate));
            }
            finally
            {
                _Conn.Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取结果集第一条数据
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="sortList"></param>
        /// <returns></returns>
        public TEntity GetFist(Expression <Func <TEntity, bool> > expression = null, object sortList = null)
        {
            try
            {
                if (_Conn.State == ConnectionState.Closed)
                {
                    _Conn.Open();
                }
                var predicate = DapperLinqBuilder <TEntity> .FromExpression(expression);

                var sort = SortConvert(sortList);
                var data = _Conn.GetSet <TEntity>(predicate, sort, 0, 1);
                return(data.FirstOrDefault());
            }
            finally
            {
                _Conn.Close();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 数据表 分页
        /// </summary>
        /// <param name="pageNum">指定页数 索引从0开始</param>
        /// <param name="pageSize">指定每页多少项</param>
        ///<param name="outTotal">输出当前表的总项数</param>
        /// <param name="expression">条件 linq表达式 谓词</param>
        /// <param name="sortList">排序字段</param>
        /// <returns></returns>
        public IEnumerable <TEntity> GetPageData(int pageNum, int pageSize, out long outTotal,
                                                 Expression <Func <TEntity, bool> > expression = null, object sortList = null)
        {
            try
            {
                if (_Conn.State == ConnectionState.Closed)
                {
                    _Conn.Open();
                }
                IPredicateGroup predicate = DapperLinqBuilder <TEntity> .FromExpression(expression); //转换Linq表达式

                IList <ISort> sort     = SortConvert(sortList);                                      //转换排序接口
                var           entities = _Conn.GetPage <TEntity>(predicate, sort, pageNum, pageSize, transaction: _Conn.BeginTransaction(IsolationLevel.ReadUncommitted));
                outTotal = _Conn.Count <TEntity>(null);
                return(entities);
            }
            finally
            {
                _Conn.Close();
            }
        }