Using entity framework to connect to multiple similar tables in .net MVC.

Posted by Dite on Stack Overflow See other posts from Stack Overflow or by Dite
Published on 2010-06-10T09:23:28Z Indexed on 2010/06/10 23:53 UTC
Read the original article Hit count: 206

A relative newcomer to .net MVC2 and the entity framework, I am working on a project which requires a single web application, (C# .net 4), to connect to multiple different databases depending on the route of access, (ie subdomain).

No problem with this in principle and all the logic is written to transform the subdomain into an entity connection and pass this through to the Entity Model.

The problem comes with the fact that the different database whilst being largely similar in structure contain 3 or 4 unique tables bespoke to that instance.

To my mind there are two ways to solve this issue, neither of which i am sure will be possible.

1/ Use a separate entity model for each database.
-Attempts down this route have through up conflicts where table/sp names are the same across differnt db's, or implicit conversion errors when I try and put the different models in different namespaces.

or

2/ Overwrite the classes which refer to the changeable database objects based on the value of a base controller property.
-I have found nothing to suggest i can even do this.


My question is if either of theser routes can ever work in principle or if i should just give up on the EF and connect to the dtabases directlky using ADO. Perhaps there is another way to solve this problem i haven't thought of?

Thanks for any help...

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc