예제 #1
0
        public IEnumerable <T> QueryItems <T>(Expression <Func <T, bool> > predicate, Tuple <bool, Expression <Func <T, object> > > isOrderByASC = null, Tuple <bool, Expression <Func <T, object> > > isThenByASC = null)
            where T : class, new()
        {
            try
            {
                SQLinq <T> query = new SQLinq <T>().Where(predicate);

                if (isOrderByASC != null)
                {
                    if (isOrderByASC.Item1)
                    {
                        query.OrderBy(isOrderByASC.Item2);
                    }
                    else
                    {
                        query.OrderByDescending(isOrderByASC.Item2);
                    }
                }

                if (isThenByASC != null)
                {
                    if (isThenByASC != null)
                    {
                        query.ThenBy(isThenByASC.Item2);
                    }
                    else
                    {
                        query.ThenByDescending(isThenByASC.Item2);
                    }
                }

                using (IDbConnection dbConnection = new SqlConnection(this.ConnectionString))
                {
                    dbConnection.Open();

                    return(dbConnection.Query <T>(query));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }