Custom table prefixes with .Net OR / M?

In a web application such as 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 additional databases that are optional), this is very useful for your users when your database objects (tables, views, restrictions and stored procedures) have a common prefix. For applications familiar with database shortages, it is typical to have a string encoded table prefix. However, I want more. In particular, I would like to have a table prefix that users can assign in the web.config file (with the corresponding default, of course).

Since I hate coding CRUD operations manually, I prefer to work through a competent OR / M and used (and enjoyed) LINQ to SQL, Subsonic and ADO.Net. I have trash in a new project, however, when it comes to entering the table prefix in the web.config user file. Are there any .NET-based OR / M products that can handle this script elegantly?

So far, the best I've been able to come up with is to use LINQ to SQL with an external mapping file, which I will have to somehow update based on the hypothetical web.config parameter.

Does anyone have a better solution? I tried to do this in the Entity Framework, but it quickly turned into a mess. (Due to my ignorance with EF? Maybe.) How about SubSonic? Is it possible to apply the table prefix in addition to the code generation time?

+4
source share
3 answers

Now I’ve explored what needs to be done for both Entity Framework and LINQ to SQL structures, and documented the steps required for each . This is much longer than the answers here, as a rule, so that I will be content with a link to the answer, and not duplicate it here. This is relatively important for everyone, but LINQ to SQL is a more flexible solution, as well as the easiest attachment.

+2
source

LightSpeed allows you to specify INamingStrategy, which allows you to dynamically resolve table names at run time.

+1
source

Instead of using table prefixes, there is instead a user of the application that belongs to schema (in MS Sql 2005 or higher).

This means that instead of:

 select * from dbo.clientAProduct select * from dbo.clientBroduct 

You have:

 select * from clientA.Product select * from clientB.Product 
+1
source

Source: https://habr.com/ru/post/1276338/


All Articles