<p>In a web application like wiki or forums or blogging software, it is often useful to store your data in a relational database. Since many hosting companies offer a single database with their hosting plans (with additional databases costing extra) it is very useful for your users when your database objects (tables, views, constraints, and stored procedures) have a common prefix. It is typical for applications aware of database scarcity to have a hard-coded table prefix. I want more, however. Specifically, I'd like to have a table prefix that users can designate—say in the web.config file (with an appropriate default, of course).</p>
<p>Since I hate coding <a href="https://en.wikipedia.org/wiki/Create%2C_read%2C_update_and_delete" rel="nofollow noreferrer">CRUD</a> operations by hand, I prefer to work through a competent OR/M and have used (and enjoyed) LINQ to SQL, Subsonic, and ADO.Net. I'm having some thrash in a new project, however, when it comes to putting a table prefix in a user's web.config file. Are there any .Net-based OR/M products that can handle this scenario elegantly?</p>
<p>The best I have been able to come up with so far is using LINQ to SQL with an external mapping file that I'd have to update somehow based on an as-yet hypothetical web.config setting.</p>
<p>Anyone have a better solution? I tried to make it happen in Entity Framework, but that turned into a mess quickly. (Due to my unfamiliarity with EF? Possibly.) How about SubSonic? Does it have an option to apply a table prefix besides at code generation time?</p>

[{'answer_id': 11757, 'author': 'Andrew Peters', 'author_id': 608, 'author_profile': 'https://Stackoverflow.com/users/608', 'pm_score': 1, 'selected': False, 'text': '<p><a href="https://www.mindscape.co.nz/products/LightSpeed/default.aspx" rel="nofollow noreferrer">LightSpeed</a> allows you to specify an <em>INamingStrategy</em> that lets you resolve table names dynamically at runtime.</p>\n'}, {'answer_id': 12089, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 1, 'selected': False, 'text': '<p>Rather than use table prefixes instead have an application user that belongs to a <code>schema</code> (in MS Sql 2005 or above).</p>\n\n<p>This means that instead of:</p>\n\n<pre><code>select * from dbo.clientAProduct\nselect * from dbo.clientBroduct\n</code></pre>\n\n<p>You have:</p>\n\n<pre><code>select * from clientA.Product\nselect * from clientB.Product\n</code></pre>\n'}, {'answer_id': 32476, 'author': 'Jacob Proffitt', 'author_id': 1336, 'author_profile': 'https://Stackoverflow.com/users/1336', 'pm_score': 3, 'selected': True, 'text': '<p>I\'ve now researched what it takes to do this in both Entity Framework and LINQ to SQL and <a href="http://theruntime.com/blogs/jacob/archive/2008/08/27/changing-table-names-in-an-orm.aspx" rel="nofollow noreferrer">documented the steps required in each</a>. It\'s much longer than answers here tend to be so I\'ll be content with a link to the answer rather than duplicate it here. It\'s relatively involved for each, but the LINQ to SQL is the more flexible solution and also the easiest to implment.</p>\n'}]
['https://Stackoverflow.com/questions/11740', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1336/']