Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have code to switch between databases when using EF, but now also need to allow the user to choose a particular table. (The tables all use the same schema but may have different names because of the way the client updates datasets). Is there a way to do this? And if it's done can it be done without being broken by updates being made to the Entity data model?

share|improve this question
    
This is very strange. Why not use views instead of different table names? –  Emmad Kareem Sep 18 '12 at 5:59
    
@Emmad Kareem I know. I've asked that question and the answer had something to do with the way other applications generate datasets for various geographic areas. –  Stonetip Sep 18 '12 at 14:13
    
Folks, please see note below in response to World Engineer's answer. I've decided we're just not going to pursue this avenue anyway. –  Stonetip Sep 18 '12 at 14:14
add comment

1 Answer

This blog post goes into some detail: Changing Entity Framework model at runtime. It's apparently fairly difficult.

Out of the box there is no way, or at least not an easy one, to change table or schema names used by the Entity Framework at runtime...

On CodePlex however you can find an adapter for your Entity Framework model to change it at runtime. You can change the connection to the database, change table names or use different schemas...

So we’re all set to support multi tenancy? Not quite...

For a multi tenant application we need a different model for each of our customers so we need to make another change to the code as available in the CodePlex project. If you don’t mind taking the performance hit to rewrite the mapping every single time an object context is created you can just open the ConnectionAdapter class and change the static variables which hold the model information to instance variables...

share|improve this answer
2  
Link only answers are bad answers. While it may be difficult is there any information you can include in the answer? –  ChrisF Sep 18 '12 at 12:58
    
@World Engineer Thanks for the link. I had come across that in my own research earlier. My thoughts were that it wasn't worth it. Incidentally, since some of our code base relies on ADO.NET and it supports async and await now (unlike EF), I've decided to just leave EF out of the project. –  Stonetip Sep 18 '12 at 14:11
    
@Stonetip: Not using EF for this scenario was the best and IMHO the only correct solution for this case. You should post it as an answer to your question. –  Ladislav Mrnka Sep 27 '12 at 7:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.