0

The application I develop is deployed to severeal environments (development, test, staging, production).

While developing I created the entity model from the existing development-database. Everything works fine, but as I wanted to put the application onto the test-environment, I realized the following problem:

The structure of the database is identical in all environments, but the database schema changes from environment to environment. For example there's a Customers table in every database. On my local dev machine it has the schema dbo ([dbo].[Customers]), but in the test environment the schema is test ([test].[Customers]), whilst the schema is stag in the staging environment ([stag].[Customers]) and so forth.

So when I deploy the application in the test environment, it gets no data from the database, because the entity framework expects the data to be found in [dbo].[Customers] but there is no such table, there is just a [test].[Customers].

I know, that I can define a schema other than dbo, but this doesn't help me, because I need a different schema depending on the deployment environment.

Any suggestions? Somehow I think I'll be ending up, asking my DB admin to change the schema to dbo in every database in each environment...

1
  • The latter option is best anyway, because one day you may want to use schemas for other purposes, e.g. segregating logical parts of your data model. And UDF's must be prefixed with their schema name when used in a query. Quite a nuisance when writing stored procedures that use UDF's. Commented May 23, 2012 at 20:17

1 Answer 1

2

If you are using code first you have to use fluent API approach from linked question and load current schema from configuration file (you will have to modify configuration per each deployment).

If you are using ObjectContext with EDMX you can use Model adapter. Other way which works with DbContext as well is storing EF metadata in files and executing some code which will change schema in ssdl file at application startup.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.