Entity framework does not create mdf file

Asked

Viewed 262 times

1

In my ASP.net MVC5 project he creates the default database by Visual Studio 2013.

I went to the App_data folder and deleted the database mdf file, as well as the log file.

I’m wanting him to create that file again.

In my configuration file, I have the following code.

   public class UserDBContext: DbContext 
    {

        public UserDBContext(): base("ConnectionString") 
        {
            Database.SetInitializer<UserDBContext>(new CreateDatabaseIfNotExists<UserDBContext>());

        }
        public DbSet<Cliente> Clientes{ get; set; }
        public DbSet<Topico> Topicos{ get; set; }
    }

It passes, and does not give any error, however it does not create database file.

  • Do you have any code that uses the context class, accessing the DbSets? The RU uses a strategy of Lazy Evaluation which only executes the code when needed.

1 answer

3


To recreate the MDF, right-click the project > Add > New Item, and choose the option Service Based Database or else Service-Based Database:

Banco de Dados Baseado em Serviço

Migrations should work normally. Just run that tables are recreated inside your file. Don’t forget to update your Connection String.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.