public void MultipleDatabaseSupport_PersistTwoEntitiesInTwoDbs_AndFetchThem_ShouldFetch() { try { SetupTables(); ITransaction txDb1 = CreateTransaction(ConnectionDb1); int id = 35; var db1Entity = new MultiDbEntity(); db1Entity.IdCol = id; db1Entity.Name = DB1Name; db1Entity.Persist(txDb1); txDb1.Commit(); ITransaction txDb2 = CreateTransaction(Connection); var db2Entity = new MultiDbEntity(); db2Entity.IdCol = id; db2Entity.Name = DB2Name; db2Entity.Persist(txDb2); txDb2.Commit(); txDb1 = CreateTransaction(ConnectionDb1); var db1LoadedEntity = new MultiDbEntity(); LoadWithId(txDb1, db1LoadedEntity, id); Assert.AreEqual(db1LoadedEntity.Name, DB1Name); txDb1.Commit(); txDb2 = CreateTransaction(Connection); var db2LoadedEntity = new MultiDbEntity(); LoadWithId(txDb2, db2LoadedEntity, id); Assert.AreEqual(db2LoadedEntity.Name, DB2Name); } catch (System.Exception e) { Assert.Fail(e.Message); } }
private bool LoadWithId(ITransaction tx, MultiDbEntity loadEntity, int id) { bool loaded = false; IDbCommand cmd = tx.CreateCommand(); cmd.CommandText = "select * from multi_db_test_root where id_col = ?"; IDbDataParameter parameter = cmd.CreateParameter(); cmd.Parameters.Add(parameter); parameter.DbType = DbType.Int32; parameter.Value = id; IDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { loadEntity.Retrieve(reader, tx); loaded = true; } return(loaded); }