Hi all !
I'm (still) using LLBLGEN V2.6 demo
I'm trying to override DataAccessAdapterBase:: OnSaveEntity method to add a particular logic.
When writing data in the database (for instance when saving an entity), depending on the current schema used (I'm using PostgresSQL 8.3), I want to choose between several different databases, i.e. I want to decide on which database the entity will be actually saved.
This logic is necessary as we have implemented a multi-master replication cluster, and for a given schema we can only write data on one particular database (that is "master" for this schema). So I need to manage as many connection strings as nodes in my cluster.
On other words, I want to read all the data from the local dabase (default connection string) and forward all write statements to the correct databases.
Is it possible to do this ?
First I tried to something easy like :
protected override void OnSaveEntity (IActionQuery saveQuery, IEntity2 entityToSave)
{
// Logic to determine the connection string to use
string connectionStringToUse = ....
this.ConnectionString = connectionStringToUse;
}
But the adapter's connection is already open when the OnSaveEntity method is called... (I saw that OpenConnection is called right before PersitQueue method, which actually calls OnSaveEntity and OnBeforeSaveEntity)
Even if i do the following:
...
this.ConnectionString = connectionStringToUse;
this.CloseConnection();
this.OpenConnection();
...
It still does no work and keeps using the default connection string (provided in "Main.ConnectionString" section in the app.config file).
(Moreover, I don't really want to close the connection here since I would loose the "_keepConnectionOpen" information.)
Thx a lot for your help !
Michael