When there is no string specification with the configured class where the Entity Framework creates the tables

Asked

Viewed 53 times

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.

Rodei enable-Migrations -> worked successfully

Rodei add-Migration Nomemigration -> worked right

Rodei update-database -> worked successfully.

But it did not create in the database I had specified in Web.config, and when trying to run the update-database return it is not running pending.

I wanted to understand in this case it saves in which place this information?

This is my Web.config on 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 Class Context

using System;

namespace AppWeb2.Models
{
    public class Mycontext : DbContext
    {      
        //Classes a ser mapeadas
        public DbSet<Pessoa> Pessoa { get; set; }
    }
}
  • Put your web project as Startup Project, see if it works.

  • How is your class Contexto?

  • I updated the question by adding the Context class.

1 answer

1


Where is my data?

By default EF uses Localdb, if you did not specify for the Dbcontext constructor which was the conectionstring it probably did this.

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 create the data in that instance.
  • If SQL Express is not available, Code First will attempt to use Localdb (installed by default with Visual Studio)

Browser other questions tagged

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