Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public TDatabaseObject ReloadMe <TDatabaseObject>(DboCommand command)
        {
            var _rows = GetDataReader(command.GetCommandDefinition());

            var _ret = ReadRowsFromReader <TDatabaseObject>(_rows);

            return(_ret.FirstOrDefault());
        }
Exemplo n.º 3
0
 public bool Exists(DboCommand command)
 {
     using (var _db = this.Connection)
     {
         var _exists = _db.ExecuteScalar <long>(command.GetCommandDefinition());
         _db.Close();
         return(_exists != 0);
     }
 }
Exemplo n.º 4
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);
        }