I have the situation where I will have multiple companies accessing a single instance of my application, but I need to segregate their data to avoid accidentally loading data for another company, and to ease per-company database backups.
Ideally, I'd like to split the data up into different databases as follows:
One SQL Server database for a list of all the users, together with any tables that are common across all users / companies
N number of company specific databases, each with the same schema but different data for each company. On logging in, I would dynamically select the database for the specific user's company
I'd like to be able to query the company specific data tables, but perform joins onto the shared database (for example, so I could store a foreign key in the company database table, which joins onto the primary key of a shared table in the other database).
I've discovered SQL Server Synonyms which look like they could do the job, and it seems I can successfully join between the two databases by using a query in SQL Server Management Studio.
Is it possible to use a Synonym table in Entity Framework Code First, and if so what would my POCO classes / DbContext need to look like?
Thanks :)