Frage

I am writing a code to use postgres database. This code already using oracle specific functions and I added some function to access the postgres tables. It is required to make build that will use only postgres functionality and no need of oracle line of code and hence no need of ODAC.

http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html

There are options like adding conditional compilation for c# so not to execute the oracle specific code for postgres. Doing so will not add the ODAC based code part in the compiled dlls and hence no need of ODAC but is this the only way. As i said there are lot of projects in the Application and doing conditional compilation will create a lot of extra code.

Or what could be other alternatives to avoid the ODAC licensing.

Thanks,

function GetData()
{
 if(Postgres flag){
// code for using OracleClientFactory and initlizing the oraclecommand

}
else if(Oracle flag)
{
   // code for using postgres and initlizing the its command object
}


}
 // code to assign query to command object and execute the query
// return the resluts

catch (){}
finally{//dispoing the objects}

}

}

War es hilfreich?

Lösung

After looking into different options one possible could be to use the c# dynamic keyword. It will allow us to get the required type at run time and it could fix the compilation erros. On the same lines we can use ObjectHandle objObjectHandle = Activator.CreateInstance to create the instance at runtime and can consume it using unwrap function .

Using Activator.CreateInstance to get the object type at runtime.

ObjectHandle objObjectHandle = Activator.CreateInstance("Npgsql","Npgsql.NpgsqlDataAdapter");

to use dynamic keyword it will be required to use Microsoft.CSharp.dll version 4 , add its reference in project file. Other solution we are looking at to create a Library project and make a standard object Model for both type of databases.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top