How to programatically create Sql Azure database of type Basic/Standard edition through Enity Framework code first

前端 未结 1 615
滥情空心
滥情空心 2020-12-19 14:15

I use EF 6. My existing code is :

public void CreateOrUpdateCompanyDb(string companyDbName)
{
        try
        {
            string connectionString = _c         


        
相关标签:
1条回答
  • 2020-12-19 14:56

    The Edition of Sql Azure Database is something you can specify in Create Database command. AFAIK, you can't specify it using the connection string.

    Syntax -

    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' } 
    }
    [;]
    

    Given that, for your scenario, two options come to mind -

    1. Before using DbMigrator, explicitly write code which creates the database, if it does not exist using traditional ADO.Net.

    2. The other option which comes to mind, but I don't know enough about and you could dig into if you want to, is to somehow find a way to hook into EF, so that you could customize the Create Database command it must generate.

    0 讨论(0)
提交回复
热议问题