I have an ancient mess I\'m trying to shovel into tiers using subsonic. Trouble is, I have this scenario:
When Hal logs in, his login uses database X for lookup data
Another example of changing providers on the fly (at runtime). This one reads items from one database and saves them to another.
Use:
CopyToAnotherDB(Dock.Columns.Id, Dock.BarcodeStringColumn);
Method:
public static void CopyToAnotherDB(string identifierColumnName, TableSchema.TableColumn fakeDirtyColHack)
where E : ActiveRecord, new()
{
SqlQuery q = new Select().From();
q.ProviderName = SERVU_PROVIDER;
IList list = q.ExecuteTypedList();
string connStr = ConfigurationManager.ConnectionStrings[ARCHIVE_PROVIDER].ConnectionString;
using (SharedDbConnectionScope scope = new SharedDbConnectionScope(connStr))
{
foreach (E item in list)
{
int itemID = (int)item.GetColumnValue(identifierColumnName);
SqlQuery qry = new Select(identifierColumnName).From().Where(identifierColumnName).IsEqualTo(itemID);
int recCount = qry.GetRecordCount();
E obj = item.Clone();
obj.IsNew = recCount == 0; //determines if adding or updating
obj.IsLoaded = !obj.IsNew; //determines if adding or updating
obj.DirtyColumns.Add(fakeDirtyColHack);
obj.Save();
}
}
}