EF CTP 4 Database name configuration
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() :
开发者_如何学CDatabase.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 ?
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:
Database.DefaultConnectionFactory =
new SqlConnectionFactory("Server=MyDatabaseServer");
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:
<connectionStrings>
<add name="PicturesCatalog" connectionString="data source=.;
Initial Catalog=PicturesDatabase; Trusted_Connection=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
精彩评论