如何更改架构名称 [英] How to Change the Schema name

查看:149
本文介绍了如何更改架构名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm开发使用EF 4.1 code首先一个ASP.NET MVC应用程序。

I´m developing an ASP.NET MVC app that uses EF 4.1 Code First.

我不得不默认的架构名称(DBO)更改为另一个名字。

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

我试过这样:

public string SchemaName;

public void MyContext()
{
    SchemaName = GetSchemaName();
}

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

但不汇入作业工作。当我得到我的上下文的新实例,并调用我的一些表..生成的查询仍然与DBO架构名称。

But it´s not working. When I get a new instance of my Context and call some of my Tables.. the generated query still with "dbo" schema name.

任何人有一些想法来解决呢?

Anyone have some idea to solve that?

推荐答案

在调试模式下几个小时后,我得到的错误。

After some hours in debug mode, I get the error.

在构造函数中,我得到的connectionString模式名,设置属性(SCHEMANAME)白衣值。

At the constructor, I get the schema name on connectionString and set the property (schemaName) whit the value.

但是,当执行得到OnModelCreating()方法,我SCHEMANAME属性设置,谁知道为什么,为NULL。

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

然后我把SCHEMANAME变量固定的方法code。当我做的一切都是对的。

Then I put the schemaName variable fixed on code at the method. When I do that everything are right.

谢谢大家!

在这里,code:

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

这篇关于如何更改架构名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆