Thursday, April 19, 2012

How do you get entity's schema name using Code First (Entity Framework) and DbContext?

Our database was designed in such a way where there are various schemas for production and various equivalent schemas for test. For example, many tables rest in MyProduction schema while the same tables live in MyTest schema.

What I want to do is determine which schema a table is using so I know which one to change it to. So, by default, everything will be under the production schemas. In the OnModelCreating event of the DbContext, if I need to point to test (determined by some true/false configuration), I need to determine the production schema being used, then point it to it's test equivalent.

I'm already aware of how to set the schema but can't find how to get it. Any ideas how I can determine the schema that a table is using?

Thank You.

No comments:

Post a Comment