public IList <T> ConsultarLista(string sql, Func <IDataReader, T> TuplaParaEntidade, Dictionary <string, object> parametros = null) { var list = new List <T>(); using (Conexao) { using (Comando) { Conexao.ConnectionString = ConexaoDBFactory.ObterStringDeConexao(Tipo).ConnectionString; Comando.Parameters.Clear(); Comando.Connection = Conexao; Comando.CommandText = sql.FormatarSQL(Tipo); Conexao.Open(); Comando.AdicionarParametros(parametros); Leitor = Comando.ExecuteReader(); while (Leitor.Read()) { list.Add(TuplaParaEntidade(Leitor)); } } } return(list); }
protected int ExecutarAtualizacao(string sql, Dictionary <string, object> parametros = null, bool carregarId = true) { int id = 0; using (Conexao) { using (Comando) { Conexao.ConnectionString = ConexaoDBFactory.ObterStringDeConexao(Tipo).ConnectionString; Comando.Parameters.Clear(); Comando.Connection = Conexao; Comando.CommandText = sql.FormatarSQL(Tipo, carregarId); Conexao.Open(); Comando.AdicionarParametros(parametros); if (carregarId) { id = Convert.ToInt32(Comando.ExecuteScalar()); } else { Comando.ExecuteNonQuery(); } } } return(id); }