How to change a schema name

I am developing an ASP.NET MVC application that first uses EF 4.1 Code.

I need to change the default schema name (dbo) to another name.

I tried this:

public string SchemaName; public void MyContext() { SchemaName = GetSchemaName(); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Account>().ToTable("TB_ACC_HOLDERS", SchemaName); } 

But that does not work. When I get a new instance of my Context and call some of my tables .. the generated query is still with the schema name "dbo".

Anyone have an idea to solve this?

+6
source share
1 answer

After a few hours in debug mode, I get an error message.

In the constructor, I get the schema name on connectionString and set the (schemaName) property with this value.

But when the execution received the OnModelCreating () method, my schemaName property was set, who knows why, to NULL.

Then I put the schemaName variable in the code using the method. When I do this, everything is correct.

Thanks everyone!

Here is the code:

 protected override void OnModelCreating(DbModelBuilder modelBuilder) { //It works fine var schemaName = "SYSTEM"; modelBuilder.Entity<Account>().ToTable("TB_ACC_HOLDERS", schemaName); } 
+5
source

All Articles