ASP.MVC ENTITY Code First (strange problem)

0

I do not know if I'm doing something wrong (probably yes). But EF is persisting the data in a DB and in a table that it creates alone.

I've already repeated this step-by-step 2 times and the result is the same.

1-I create an MVC Web Solution that I call Model-Index. (The idea was to practice paging and filters, but ... I spent all day for nothing ...)

2-I create a "sub" project within a solution named Domain and create a POCO class called Student with, Id, Enroll, Name, and Note.

3-I create another "Sub" project and call it Persistence. Install the EntityFramework on it. I add an EncoderAlumniDbContext.cs class as follows:

using Dominio;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace Persistencia
{
public class CadastroAlunosDbContext : DbContext
{
    public DbSet<Aluno> Alunos { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Entity<Aluno>().ToTable("Alunos");
        base.OnModelCreating(modelBuilder);
    }
}
}

Then I go into the App.config of this project Persistence and add:

<connectionStrings>
<add name="CadastroAlunosDbContext" connectionString="Server=NB-SAUDE-03;Database=CadastroAlunos;User Id=sa;Password=Master123;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Notice that my server is called Server = NB-SAUDE-03 I even specify the database: Database = StudentCount Then I run the following commands in the PackageManagerConsole:

Enable-Migrations -ProjectName Persistence -StartUpProjectName Persistence

Add-Migration "Base Creation" -ProjectName Persistence -StartUpProjectName Persistence

Update-Database -ProjectName Persistence -StartUpProjectName Persistence

------ So far, everything works as expected ---------

I'm going to SQL Server ObjectExplorer and see that my database was created and the Students table too. All blz!

But when I run the application in the browser and ask to register a new student. This student did not appear persisted in the created bank. I was looking for and found a bank called "Persistencia.CadastroAlunosDbContext" that I do not know where it came from. It also has a Students table and the data is being persisted in it and not in what I have specified in the App.config of the Persistence project. Note: This database is being created in what appears to be another instance of SQL, but I only have one installed. Why is EF creating this bank?

    
asked by anonymous 03.11.2017 / 19:00

0 answers