Example #1
0
        /// <summary>
        /// 查询 list
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="unitOfWork"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static async Task <List <T> > Query <T>(IUnitOfWork unitOfWork, Expression <Func <T, bool> > whereLambda, SqlQuery sql = null) where T : class
        {
            var db = unitOfWork.DbConnection;

            if (sql == null)
            {
                sql = SqlQuery <T> .Builder(unitOfWork);
            }
            sql._Sql = new StringBuilder(LambdaToSqlHelper <T> .GetWhereByLambda(whereLambda, unitOfWork.DbType));
            var result = await db.QueryAsync <T>(sql.QuerySql, sql.Param);

            return(result.ToList());
        }
Example #2
0
        public static async Task <DataTable> QueryDataTable <T>(IUnitOfWork unitOfWork, Expression <Func <T, bool> > whereLambda, SqlQuery sql = null) where T : class
        {
            var db = unitOfWork.DbConnection;

            if (sql == null)
            {
                sql = SqlQuery <T> .Builder(unitOfWork);
            }
            sql._Sql = new StringBuilder(LambdaToSqlHelper <T> .GetWhereByLambda(whereLambda, unitOfWork.DbType));
            DataTable dataTable = new DataTable();
            var       result    = await unitOfWork.DbConnection.ExecuteReaderAsync(sql.QuerySql, sql.Param);

            dataTable.Load(result);
            return(dataTable);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="unitOfWork"></param>
        /// <param name="whereLambda"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static async Task <T> SingleOrDefault <T>(IUnitOfWork unitOfWork, Expression <Func <T, bool> > whereLambda, SqlQuery sql = null) where T : class
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var db = unitOfWork.DbConnection;

            if (sql == null)
            {
                sql = SqlQuery <T> .Builder(unitOfWork);
            }
            sql._Sql = new StringBuilder(LambdaToSqlHelper <T> .GetWhereByLambda(whereLambda, unitOfWork.DbType));
            var result = await db.QueryFirstOrDefaultAsync <T>(sql.QuerySql);

            return(result);
        }
Example #4
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="unitOfWork"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static async Task <int> Delete <T>(IUnitOfWork unitOfWork, Expression <Func <T, bool> > whereLambda, SqlQuery sql = null) where T : class
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var db = unitOfWork.DbConnection;

            if (sql == null)
            {
                sql = SqlQuery <T> .Builder(unitOfWork);
            }
            sql._Sql = new StringBuilder(LambdaToSqlHelper <T> .GetWhereByLambda(whereLambda, unitOfWork.DbType));
            var result = await db.ExecuteAsync(sql.DeleteSql, sql.Param);

            stopwatch.Stop();
            return(result);
        }