예제 #1
0
        public async Task <int> ExecuteAsync(string sql, object param, int?timeout = null)
        {
            var cmd = SqlFactory.CreateCommand(_conn, sql, param, CommandType.Text);

            cmd.Transaction = _trans;
            using (cmd)
            {
                return(await cmd.ExecuteNonQueryAsync());
            }
        }
예제 #2
0
        public async Task <T> ScalarAsync <T>(string sql, object param, int?timeout = null)
        {
            var cmd = SqlFactory.CreateCommand(_conn, sql, param, CommandType.Text);

            cmd.Transaction = _trans;
            using (cmd)
            {
                var obj = await cmd.ExecuteScalarAsync();

                var obj1 = TypeMap.ConvertToType(obj, typeof(T));
                return(obj1 == null ? default(T) : (T)obj1);
            }
        }
예제 #3
0
        public async Task <int> ExecuteAsync(string sql, object param, int?timeout = null)
        {
            var conn = CreateConnection(false);

            try
            {
                var cmd = SqlFactory.CreateCommand(conn, sql, param, CommandType.Text);
                await OpenConnectionAsync(conn);

                return(await cmd.ExecuteNonQueryAsync());
            }
            finally
            {
                CloseConnection(conn);
            }
        }
예제 #4
0
        public async Task <DataTable> QueryTableAsync(string sql, object param, string tableName = "p_Out", int?timeout = null)
        {
            DataTable dt = new DataTable();

            dt.TableName = tableName;
            var cmd = SqlFactory.CreateCommand(_conn, sql, param, CommandType.Text);

            cmd.Transaction = _trans;
            using (cmd)
            {
                using (var dr = await cmd.ExecuteReaderAsync())
                {
                    dt.Load(dr);
                }
            }
            return(dt);
        }
예제 #5
0
        public async Task <IEnumerable <T> > QueryAsync <T>(string sql, object param, int?timeout = null)
        {
            var cmd = SqlFactory.CreateCommand(_conn, sql, param, CommandType.Text);

            cmd.Transaction = _trans;
            using (cmd)
            {
                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    IList <T> list = new List <T>();
                    while (await reader.ReadAsync())
                    {
                        var next = SqlFactory.ResultMap.Deserializer <T>(reader);
                        list.Add((T)next);
                    }
                    return(list);
                }
            }
        }
예제 #6
0
        public async Task <T> QueryFirstOrDefaultAsync <T>(string sql, object param, int?timeout = null)
        {
            var cmd = SqlFactory.CreateCommand(_conn, sql, param, CommandType.Text);

            using (cmd)
            {
                using (var reader = await cmd.ExecuteReaderAsync())
                {
                    T result = default(T);
                    if (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        var next = SqlFactory.ResultMap.Deserializer <T>(reader);
                        result = (T)next;
                    }
                    while (await reader.NextResultAsync().ConfigureAwait(false))
                    {
                    }
                    return(result);
                }
            }
        }
예제 #7
0
        public async Task <T> ScalarAsync <T>(string sql, object param, int?timeout = null)
        {
            var conn = CreateConnection(true);

            try
            {
                var cmd = SqlFactory.CreateCommand(conn, sql, param, CommandType.Text);
                using (cmd)
                {
                    await OpenConnectionAsync(conn);

                    var obj = await cmd.ExecuteScalarAsync();

                    var obj1 = TypeMap.ConvertToType(obj, typeof(T));
                    return(obj1 == null ? default(T) : (T)obj1);
                }
            }
            finally
            {
                CloseConnection(conn);
            }
        }
예제 #8
0
 public SqlMapper(string name)
 {
     SqlFactory = new SqlFactory(name);
 }
예제 #9
0
 public SqlMapper()
 {
     SqlFactory = new SqlFactory();
 }
예제 #10
0
 private DbConnection CreateConnection(bool isReadDb)
 {
     return(SqlFactory.CreateConnection(isReadDb));
 }