views:

26

answers:

2

So, i have my database sorted like:

Products_001 Products_002 Products_003

Let's say, if a customer logs in and his id is 001, he is only entitled to use the database-table products_001.

Can i dynamically create his model - entity using Asp.Net MVC, and how would i do this?

+4  A: 
ProductsBase products = Activator.CreateInstance(
    "YourAssembly.Namespace", 
    "Products_" + Login.Id);

http://msdn.microsoft.com/en-us/library/d133hta4.aspx

You may need to have a base type/interface for your different product types

Anthony Johnston
Nice solution, I have not seen Activator before ....
abarr
Is this solution scalable?Eg. let's say the client uses this "custom model" for his website. => client 1 has website 1 and uses table product_001- client 2 has website 2 and uses table product_002
NicoJuicy
thats probably another question, do you have this structure in place or are you considering it for a design?
Anthony Johnston
I am considering it for design at work.
NicoJuicy
A: 

NicoJuicy,

The way we handled this was to have a generic model (Using EF) and different DB's for each table. When the user logs in we bind the Model to the appropriate Db using the connection string and the user info.

If this sounds like what you want let me know and I will post more details.

Andrew

abarr
I think this solution is very resource intensive (correct me if i'm wrong)
NicoJuicy
I probably fudged the answer a bit as we have a multi tenancy app so as soon as they login we bind the EF Model to that clients db and that is it for the entire session.
abarr