我使用EF 6.我现有的代码是:
- public void CreateOrUpdateCompanyDb(string companyDbName)
- {
- try
- {
- string connectionString = _connectionStringProvider.GetConnectionString(companyDbName);
- DbMigrationsConfiguration cfg = CreateMigrationsConfig(connectionString);
- cfg.AutomaticMigrationsEnabled = false;
- cfg.AutomaticMigrationDataLossAllowed = false;
- DbMigrator dbMigrator = new DbMigrator(cfg);
- dbMigrator.Update();
- }
- catch (MigrationsException exception)
- {
- _logger.Error(string.Format("Error creating company database '{0}'",companyDbName),exception);
- }
- }
连接字符串如下:
- Server=tcp:xxx.database.windows.net,1433;Database=companyDbName;User ID=xxx@xxx;Password=xxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
这为特定公司创建了数据库.但问题是创建的数据库来自现已退役的网络版,但我想创建基本/标准/高级版.
我应该如何操作连接字符串,以便数据库的版本是所需的?
解决方法
您可以在
AFAIK,您无法使用连接字符串指定它.
Create Database
命令中指定sql Azure数据库版本.
AFAIK,您无法使用连接字符串指定它.
句法 –
- CREATE DATABASE database_name [ COLLATE collation_name ]
- {
- (<edition_options> [,...n])
- }
- <edition_options> ::=
- {
- MAXSIZE = { 100 MB | 500 MB | 1 | 5 | 10 | 20 | 30 … 150…500 } GB
- | EDITION = { 'web' | 'business' | 'basic' | 'standard' | 'premium' }
- | SERVICE_OBJECTIVE = { 'shared' | 'basic' | 'S0' | 'S1' | 'S2' | 'P1' | 'P2' | 'P3' }
- }
- [;]
鉴于此,对于您的方案,我会想到两个选项 –
>在使用DbMigrator之前,如果使用传统的ADO.Net不存在,则显式编写创建数据库的代码.>想到的另一个选项,但我不太了解你可以深入研究,如果你想,是以某种方式找到一种方法来挂钩到EF,这样你就可以自定义它必须生成的Create Database命令.