Exemplo n.º 1
0
        public int Count <T>(IDbConnection connection, Expression <Func <T, bool> > exp, IDbTransaction transaction, int?commandTimeout) where T : class
        {
            string str = SqlExpession.Where <T>(exp);
            string sql = string.Format("select count(1) from {0} where {1}", typeof(T).Name, str);

            return(connection.Query <int>(sql, null, transaction, false, commandTimeout, CommandType.Text).Single());
        }
Exemplo n.º 2
0
        public IEnumerable <T> Where <T>(IDbConnection connection, Expression <Func <T, bool> > exp, string orderBy, IDbTransaction trans, int?timeout, bool buffered) where T : class
        {
            string str = SqlExpession.Where <T>(exp);

            if (string.IsNullOrWhiteSpace(orderBy))
            {
                IClassMapper classMap = SqlGenerator.Configuration.GetMap <T>();
                orderBy = SqlGenerator.GetOrderBy(classMap);
            }
            return(connection.Query <T>(string.Format("select * from {0} where {1} order by {2}", typeof(T).Name, str, orderBy), null, trans, buffered, timeout));
        }
Exemplo n.º 3
0
        public IEnumerable <T> Where <T>(IDbConnection connection, Expression <Func <T, bool> > exp, string orderBy, int pageIndex, int pageSize, IDbTransaction trans, int?timeout, bool buffered) where T : class
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("WITH Data_DataSet AS");
            sb.Append("(SELECT ROW_NUMBER() OVER (ORDER BY " + orderBy + ") AS Row, * FROM (");
            string str = SqlExpession.Where <T>(exp);

            sb.Append(string.Format("select * from {0} where {1}", typeof(T).Name, str));
            sb.Append(")aa)");
            sb.Append("SELECT * FROM Data_DataSet");
            sb.Append(string.Format(" WHERE Row between ({0}*{1}+1) and ({1}*({0}+1))", pageIndex, pageSize));
            return(connection.Query <T>(sb.ToString(), null, trans, buffered, timeout));
        }