I'm trying to find a generic way for multiple db connection support.
private void ExecuteCommand(string connStr, Action<NpgsqlConnection> task)
{
using (var conn = new NpgsqlConnection(connStr))
{
conn.Open();
task(conn);
}
}
I have 2 Databases which are sql and postgresql. I dont want to duplicate my function 2 of them. So I need something like that:
if (db == sql) new sqlConnection() else new NpsqlConnection()
How can i do that in simple way?