11

Is is possible to set the Recovery Model mode of an SQL database created using Entity Framework 6? I know it's possible to set it through the following SQL statement:

ALTER DATABASE [Database_Name] SET RECOVERY SIMPLE;

It seems odd that this can't be set as a part of the configuration of the DbContext - the object which creates the database can't seem to control how it's created. I was expecting to find something like the following:

public class MyContext : DbContext
{
    public MyContext(string connectionString) : base(connectionString)
    {
        // This is where I would have expected to be able to set the recovery model type
        Database.RecoveryModel = RecoveryModelType.Simple;
    }
}

My suspicion is that this isn't possible due to EF being (largely) DB provider agnostic and recovery model being MSSQL specific, but I'm hoping that I'm wrong.

6
  • Of course, you can Commented Jul 3, 2017 at 9:44
  • stackoverflow.com/questions/24594365/… Commented Jul 3, 2017 at 10:03
  • @Coding4Fun just because that question has 'recovery' in the title, doesn't mean it's talking about the same thing - it isn't. Commented Jul 3, 2017 at 10:06
  • @Coding4Fun The linked question doesn't address the question I asked, which is specifically about setting the recovery model type through EF. The database is being created absolutely fine, but the recovery model is always the default; that is, full. Commented Jul 3, 2017 at 10:06
  • The fact that this github.com/aspnet/EntityFramework6/blob/master/src/… (which is where CREATE DATABASE is to be found in the EF6 source) doesn't include any mention of "recovery" suggests that the answer is no. Commented Jul 3, 2017 at 13:36

1 Answer 1

1

Not in a way you want it to.

EF works with different SQL providers and what is relevant for MS SQL, might be inappropriate for MySQL.

However you can always run raw TSQL and do whatever you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.