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?

  • This is very strange. Why not use views instead of different table names?
    – NoChance
    Commented Sep 18, 2012 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
    Commented Sep 18, 2012 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
    Commented Sep 18, 2012 at 14:14

1 Answer 1


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...

  • 2
    Link only answers are bad answers. While it may be difficult is there any information you can include in the answer?
    – ChrisF
    Commented Sep 18, 2012 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
    Commented Sep 18, 2012 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. Commented Sep 27, 2012 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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