在使用代码之后更改实体框架数据库模式映射 [英] Change Entity Framework database schema map after using code first
问题描述
EF正在使用[DBO]模式针对本地SQL Express实例运行。
现在我想发布博客,而我已经完成了以下:
- 从SQL Express创建表和所有对象的脚本,并将[dbo]从我的服务器更改为[管理员]模式。
- 将脚本反对服务器。没有问题,所有的对象都创建了一个填充好的。
- 我已经修改了Webconfig,并添加了我的BlogContext连接字符串来指向服务器不是本地的sql express。
- 发布网站
我得到的错误是:无效的对象名称'dbo.Articles'。 - 文章是我的实体之一。它驻留在我的sql服务器上, [管理员]。文章
。
据我所知,EF仍然认为im使用DBO模式。虽然我已经添加了连接字符串来指向管理员用户。
如何更改EF认为应该使用的模式?
如果没有通过数据注释或流畅的API明确配置模式,EF将使用 dbo
模式。
[Table(MyTable,MySchema)]
public class MyEntity
{
}
或
modelBuidler.Entity< MyEntity>()。ToTable(MyTable,MySchema);
I've finished building my blog using EF and Code First.
EF was running against my local SQL Express instance, with [DBO] schema.
Now i want to publish the blog, and i have done the following :
- Generetade the scripts for the tables and all objects from SQL Express and change [dbo] to my [administrator] schema from my server.
- Ran the scripts against the server. No issues, all objects were created an populated just fine.
- I have modified Webconfig and added my BlogContext connection string to point to the server not local sql express.
- Published the site.
The error i am getting is : Invalid object name 'dbo.Articles'. - where Articles is one of my entities. It resides on my sql server, [Administrator].Articles
.
As far as i can tell EF still thinks im using the DBO schema. Although i have added the connection string to point to administrator user.
How can i change the schema that EF thinks it should use?
EF will use dbo
schema if you didn't configure the schema explicitly through data annotations or fluent API.
[Table("MyTable", "MySchema")]
public class MyEntity
{
}
Or
modelBuidler.Entity<MyEntity>().ToTable("MyTable", "MySchema");
这篇关于在使用代码之后更改实体框架数据库模式映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!