Exemple #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());
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
        }
Exemple #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);
                }
            }
        }
Exemple #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);
                }
            }
        }
Exemple #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);
            }
        }
Exemple #8
0
 public SqlMapper(string name)
 {
     SqlFactory = new SqlFactory(name);
 }
Exemple #9
0
 public SqlMapper()
 {
     SqlFactory = new SqlFactory();
 }
Exemple #10
0
 private DbConnection CreateConnection(bool isReadDb)
 {
     return(SqlFactory.CreateConnection(isReadDb));
 }