Entity Framework automatically creates database when it doesn't exist

Søren Pedersen 21 Reputation points
2020-09-21T06:51:29.73+00:00

We have a problem that is unfortunately costing us alot of money. We are using MVC 5 with Entity Framework 6. Our problem is, if we are using a database that doesn't exist, it will create it, but it creates a General Purpose Gen5 database. As we usually use a basic, this is a huge expense. We sometimes doesn't notice this as we have alot of small databases, and our cost skyrockets. Is there a way to change this?

Azure SQL Database
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,933 questions
0 comments No comments
{count} votes

Accepted answer
  1. KalyanChanumolu-MSFT 8,351 Reputation points
    2020-09-21T17:04:20.337+00:00

    @Søren Pedersen Thank you for reaching out.

    Unfortunately, you cannot initialize properties like ServiceTier, Database size from EF6.
    Are you deploying the database using a release pipeline? Your best bet would be to execute an SQL statement after the deployment depending on the environment

    ALTER DATABASE [YourDBName] MODIFY(EDITION = 'Standard', SERVICE_OBJECTIVE = 'S1', MAXSIZE = 20 GB);   
    

    EF Core 3.1 has support to configure these while creating the Model

    Protected override void OnModelCreating(ModelBuilder modelBuilder)  
    {  
          modelBuilder.HasServiceTier("Standard");  
      
          modelBuilder.HasPerformanceLevel("S1");  
    
          modelBuilder.HasDatabaseMaxSize("20 GB");  
    }  
    

    Please let me know if you have any further questions.

    --

    If an answer is helpful, please "Accept answer" or "Up-Vote" for the same which might be beneficial to other community members reading this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.