コード例 #1
0
ファイル: SqlSession.cs プロジェクト: szm7410/SNData
        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;
            }
        }