EF CTP 4 数据库名称配置
例如,我使用这个连接字符串:
<connectionStrings>
<add name="PicturesDatabase"
connectionString=" Server=.;
Database=SomeprojectDatabase;
Trusted_Connection=True;"
providerName="System.Data.SqlClient"/>
<../>
然后我在 Application_Start() 中使用它:
Database.DefaultConnectionFactory =
new SqlConnectionFactory(ConfigurationManager.
ConnectionStrings["PicturesDatabase"].ConnectionString);
在我的数据库中,我得到了这个非常奇怪的新数据库: MyAppNamespace.Models.PicturesCatalog 有两个表 dbo.EdmMetadata 和 dbo.Pictures
表很好,但为什么不创建一个名为 PicturesDatabase 的新数据库(如连接字符串)与那些表?
我已经尝试删除此表几次,我确实尝试创建 PicturesDatabase 并使用它...但它仍然生成此 MyAppNamespace.Models.PicturesCatalog。它有什么问题呢?我该如何解决它?
For sample I'm using this connection string :
<connectionStrings>
<add name="PicturesDatabase"
connectionString=" Server=.;
Database=SomeprojectDatabase;
Trusted_Connection=True;"
providerName="System.Data.SqlClient"/>
<../>
And then I use it in Application_Start() :
Database.DefaultConnectionFactory =
new SqlConnectionFactory(ConfigurationManager.
ConnectionStrings["PicturesDatabase"].ConnectionString);
And in my database I get this really strange new Database :
MyAppNamespace.Models.PicturesCatalog
with two tables dbo.EdmMetadata and dbo.Pictures
Tables are fine, but why doesn't it create a new database named PicturesDatabase (as in connection string) with those tables ?
I've tried dropping this table few times, I did try creating PicturesDatabase and using it... but it still generates this MyAppNamespace.Models.PicturesCatalog. What is the problem with it ? And how do I fix it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
System.Data.Entity.Infrastruct.SqlConnectionFactory
不适合以这种方式使用。这个连接工厂包含一个构造函数,它允许我们覆盖最终连接字符串的部分,例如用户名、密码和服务器,而不是整个。例如,我们可以像这样更改数据库服务器:
您在这里尝试执行的操作可以通过在 app.config 中提供一个与 DbContext 名称匹配的连接字符串来轻松完成 - 我假设它是图片目录:
System.Data.Entity.Infrastructure.SqlConnectionFactory
is not meant to use in this way. This connection factory includes a constructor that allows us to override pieces of the final connection sting, such as username, password and server and not the whole thing.For example, we can change the Database Server like this:
What you try to do here can be easily accomplished by providing a connection string in your app.config that matches the name of your DbContext - I assume it's PicturesCatalog: