When it does not have a string specification with the configured class where the Entity Framework creates the tables

2

I created a new project using Asp.Net MVC with EF, and did not configure the connection string property with the same name as the context class: DbContext in Web.config.

Rodei enable-migrations - > worked successfully

Rodei add-migration NomeMigration - > It worked fine

Rodei update-database - > worked successfully.

But did not create in the database that I had specified in Web.config, and when trying to run the update-database return that is unresolved to execute.

I wanted to understand in this case it saves where that information?

This is my Web.config in the connection part.

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
    <add name="conexao" connectionString="Data Source=localhost;Initial Catalog=bancoDB;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

My Context class

using System;

namespace AppWeb2.Models
{
    public class Mycontext : DbContext
    {      
        //Classes a ser mapeadas
        public DbSet<Pessoa> Pessoa { get; set; }
    }
}
    
asked by anonymous 28.09.2017 / 15:48

1 answer

1

Where are my data?

By default EF uses the LocalDb, if you did not specify for the DbContext constructor what the connectionstring was, it probably did it.

By convention , DbContext create a database for you.

  • If a local instance of SQL Express is available (installed by default with Visual Studio), Code First creates the database this instance.
  • If SQL Express is not available, Code First will attempt to use the LocalDb (installed by default with Visual Studio)
09.01.2018 / 18:21