コード例 #1
0
        public IEnumerable <TDatabaseObject> Query <TDatabaseObject>(DboCommand command, bool useFieldNames = true)
        {
            try
            {
                var _ret = new List <TDatabaseObject>();

                if (useFieldNames)
                {
                    var _rows = GetDataReader(command.GetCommandDefinition());

                    _ret = ReadRowsFromReader <TDatabaseObject>(_rows);
                }
                else
                {
                    using (var _conn = this.Connection)
                    {
                        _ret = _conn.Query <TDatabaseObject>(command.GetCommandDefinition()).ToList();
                        _conn.Close();
                    }
                }

                return(_ret);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
コード例 #2
0
        private static DboCommand GetDboCommand(Expression <Func <T, bool> > predicate = null, bool useFieldNames = true, SqlStatementsTypes sqlType = SqlStatementsTypes.Select, object obj = null)
        {
            var _tableDef     = TableDefinition.GetTableDefinition(typeof(T));
            var _selectFields = _tableDef.GetStatementSelect(sqlType == SqlStatementsTypes.SelectReload);

            DboCommand _sqlCommand = null;

            switch (sqlType)
            {
            case SqlStatementsTypes.Select:
                _sqlCommand = GetCommandSelect(_selectFields, predicate, _tableDef);
                break;

            case SqlStatementsTypes.DeleteAll:
                _sqlCommand = GetCommandDelete(predicate);
                break;

            case SqlStatementsTypes.SelectReload:
                _sqlCommand = GetCommandSelectReloadMe(_selectFields, obj);
                break;

            default:
                throw new NotImplementedException();
            }

            return(_sqlCommand);
        }
コード例 #3
0
        public TDatabaseObject ReloadMe <TDatabaseObject>(DboCommand command)
        {
            var _rows = GetDataReader(command.GetCommandDefinition());

            var _ret = ReadRowsFromReader <TDatabaseObject>(_rows);

            return(_ret.FirstOrDefault());
        }
コード例 #4
0
 public bool Exists(DboCommand command)
 {
     using (var _db = this.Connection)
     {
         var _exists = _db.ExecuteScalar <long>(command.GetCommandDefinition());
         _db.Close();
         return(_exists != 0);
     }
 }
コード例 #5
0
        public CrudReturn DeleteAll <TDatabaseObject>(DboCommand command, TransactionObject transaction = null)
        {
            var _table = TableDefinition.GetTableDefinition(typeof(TDatabaseObject));
            var _ret   = new CrudReturn
            {
                ReturnStatus    = CrudStatus.Ok,
                RecordsAffected = -1,
                ChangeType      = SqlStatementsTypes.DeleteAll,
                ReturnMessage   = "Dados excluídos com sucesso!"
            };

            var _transaction = transaction ?? new TransactionObject(true);

            try
            {
                if (_transaction.Connection == null)
                {
                    _transaction.SetConnection(_table.DefaultDataFunction.Connection);
                }

                _ret.RecordsAffected = _transaction.Connection.Execute(command.GetCommandDefinition());

                if (_transaction.AutoCommit)
                {
                    _transaction.Commit();
                    _transaction.Dispose();
                }
            }
            catch (Exception ex)
            {
                _ret.ReturnMessage = string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace);
                _ret.ReturnStatus  = CrudStatus.Fail;
            }

            return(_ret);
        }
コード例 #6
0
 public async Task <bool> ExistsAsync(DboCommand command)
 {
     return(await Task.Run(() => this.Exists(command)));
 }
コード例 #7
0
 public async Task <CrudReturn> DeleteAllAsync <TDatabaseObject>(DboCommand command, TransactionObject transaction = null)
 {
     return(await Task.Run(() => this.DeleteAll <TDatabaseObject>(command, transaction)));
 }
コード例 #8
0
 public async Task <TDatabaseObject> ReloadMeAsync <TDatabaseObject>(DboCommand command)
 {
     return(await Task.Run(() => this.ReloadMe <TDatabaseObject>(command)));
 }
コード例 #9
0
 public async Task <IEnumerable <TDatabaseObject> > QueryAsync <TDatabaseObject>(DboCommand command, bool useFieldNames = true)
 {
     return(await Task.Run(() => this.Query <TDatabaseObject>(command, useFieldNames)));
 }
コード例 #10
0
 public TDatabaseObject Load <TDatabaseObject>(DboCommand command)
 {
     return(this.Query <TDatabaseObject>(command).FirstOrDefault());
 }
コード例 #11
0
 public async Task <TDatabaseObject> LoadAsync <TDatabaseObject>(DboCommand command)
 {
     return(await Task.Run(() => this.Load <TDatabaseObject>(command)));
 }