[英]Entity Framework Code First - Specify server to use but not the database
I am trying to use EF CF to create multiple databases using the same schema. 我正在尝试使用EF CF使用相同的架构创建多个数据库。 I want the flexibility to be able to specify which server I want my database created in, and specify the database name during runtime. 我希望能够灵活地指定要在其中创建数据库的服务器,并在运行时指定数据库名称。
So, in sum, given a server, I want to be able to specify what database to create (or use existing) in runtime. 因此,总而言之,给定一台服务器,我希望能够指定要在运行时创建(或使用现有数据库)的数据库。 AFAIK, using the connection string forces me to specify the database as well, so that's not good. AFAIK,使用连接字符串会迫使我也指定数据库,所以不好。
A more thorough search came up with this, and it works just as I needed. 对此进行了更彻底的搜索,它可以按照我的需要工作。
Add this to the configuration file 将此添加到配置文件
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=MyDatabaseServer; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
where "MyDatabaseServer" could be your ".\\SQLEXPRESS" instance, or whatever. 其中“ MyDatabaseServer”可以是您的“。\\ SQLEXPRESS”实例,或其他任何实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.