Exemplo n.º 1
0
        public async Task <T> ExecuteScalarAsync <T>(Sql Sql)
        {
            var sql  = Sql.SQL;
            var args = Sql.Arguments;

            try
            {
                OpenSharedConnectionInternal();
                using (var cmd = CreateCommand(_sharedConnection, sql, args))
                {
                    object val = await ExecuteScalarHelperAsync(cmd).ConfigureAwait(false);

                    if (val == null || val == DBNull.Value)
                    {
                        return(await TaskAsyncHelper.FromResult(default(T)).ConfigureAwait(false));
                    }

                    Type t = typeof(T);
                    Type u = Nullable.GetUnderlyingType(t);

                    return((T)Convert.ChangeType(val, u ?? t));
                }
            }
            catch (Exception x)
            {
                OnExceptionInternal(x);
                throw;
            }
            finally
            {
                CloseSharedConnectionInternal();
            }
        }
Exemplo n.º 2
0
 public virtual Task <int> DeleteAsync(string tableName, string primaryKeyName, object poco, object primaryKeyValue)
 {
     return(DeleteImp(tableName, primaryKeyName, poco, primaryKeyValue, ExecuteAsync, TaskAsyncHelper.FromResult(0)));
 }
Exemplo n.º 3
0
 public virtual Task <int> UpdateAsync(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable <string> columns)
 {
     return(UpdateImp(tableName, primaryKeyName, poco, primaryKeyValue, columns,
                      async(sql, args, next) => next(await ExecuteAsync(sql, args).ConfigureAwait(false)), TaskAsyncHelper.FromResult(0)));
 }