Hi Otis, thanks for sticking with me.
Again I can't answer for every db developer who has done it, but I've come across many web apps that, at installation time, allow the admin to specify a table prefix before the tables are created for the first time. He can choose any prefix he wants, and I as a developer cannot predit it until my app is running on his system.
In the case of DNN, the "object qualifier" is specified at installation time and is written to web.config after the tables are created. Anyone wishing to access DNN's tables or to fully follow the DNN deployment scenarios must also create his tables using this object qualifier.
In general, the strategy is seen more in mySQL backends and less in SQL Server, but I have seen both. Because this practice is out there (even if it doesn't make sense), I have to work with it and that means not knowing the exact table name until runtime. There may not be a good reason for doing it
In testing, I was able to add a table prefix to the PersistenceInfoProviderCore class and recompile. Could I alter the LLBL templates to expose these mappings through properties for modification at runtime?
Here is a unit test that I would like to make.
[TestFixture]
public class TablePrefixFixture
{
[Test]
public void TablePrefix()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["Main.ConnectionString"]);
conn.Open();
SqlCommand c = new SqlCommand("EXEC sp_rename 'BlogEntry', '" + GetPrefix() + "BlogEntry'", conn);
c.ExecuteNonQuery();
DataAccessAdapter da = new DataAccessAdapter();
// da.SetPrefix(GetPrefix()); // Add a call to set a prefix at runtime
BlogEntryEntity be = new BlogEntryEntity();
be.Title = "test title";
be.Body = "test body";
da.SaveEntity(be);
c = new SqlCommand("EXEC sp_rename 'DNN_NukeSpace_BlogEntry', 'NukeSpace_BlogEntry'", conn);
c.ExecuteNonQuery();
conn.Close();
}
// Simulate some API call to retrieve the current table prefix
string GetPrefix()
{
return "TestPrefix_";
}
}
Multiple installations sharing a single catalog is a fringe scenario and I can get by without solving it for now, but it is something that occurs out in the wild.