/// <summary>
        /// Lee la tabla base y retorna entidad con Id coincidente o null.
        /// </summary>
        /// <param name="Id">Entero que especifica la clave principal PK de la entidad.</param>
        /// <returns>Objeto del tipo Entidad definido en clase derivada.</returns>
        public T ReadEntityById(int Id)
        {
            T ent = default(T);

            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command, Id))
                {
                    command.Parameters.Add(param);
                }

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <T> mapper = GetMapper();
                            ent = mapper.MapEntity(reader);
                            return(ent);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Beispiel #2
0
        public override ClaveMes ReadEntityBy2Params(int mes, int anno)
        {
            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command))
                {
                    command.Parameters.Add(param);
                }

                // Creando Parametro para filtrar por Mes y Anno
                IDataParameter param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterOneParam;
                param1.DbType        = DbType.Int32;
                param1.Value         = mes;
                command.Parameters.Add(param1);

                param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterTwoParam;
                param1.DbType        = DbType.Int32;
                param1.Value         = anno;

                command.Parameters.Add(param1);

                ClaveMes ent = null;

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <ClaveMes> mapper = GetMapper();
                            ent = mapper.MapEntity(reader);
                            return(ent);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }