I'm using the Oracle.ManagedDataAccess.Client, it is referenced to the project containing the context.
I have my Context:
namespace Generico.Repositorio
{
public class Contexto : IDisposable
{
private readonly OracleConnection minhaConexao;
public Contexto()
{
minhaConexao = new OracleConnection(ConfigurationManager.ConnectionStrings["Conexao"].ConnectionString);
minhaConexao.Open();
}
public void ExecutaComando(string strQuery)
{
var cmdComando = new OracleCommand
{
CommandText = strQuery,
CommandType = CommandType.Text,
Connection = minhaConexao
};
cmdComando.ExecuteNonQuery();
}
public OracleDataReader ExecutaComandoComRetorno(string strQuery)
{
var cmdComando = new OracleCommand(strQuery, minhaConexao);
return cmdComando.ExecuteReader();
}
public void Dispose()
{
if (minhaConexao.State == ConnectionState.Open)
minhaConexao.Close();
}
}
}
In the application I have an error: "The 'OracleDataReader' type is defined in an assembly that is not referenced. You should add a reference to the assembly 'Oracle.ManagedDataAcces'
namespace Generico.Aplicacao
{
public class AtualizaAplicacao
{
private Contexto contexto;
public string Consulta(string codigo)
{
int retorno = 0;
var strQuery = "";
//apensas vamos retornar o pais, não vamos gravar ou atualizar
strQuery = string.Format("select * from pais WHERE codigo = '{0}' ", codigo);
using (contexto = new Contexto())
{//erro em contexto.ExecutaComandoComRetorno
var reader = contexto.ExecutaComandoComRetorno(strQuery);
while (reader.Read())
{
//pega o Id da cidade
retorno = Convert.ToInt32(reader["codigo"]);
}
reader.Close();
}
return retorno.ToString();
}
}
}