0
I did it in a separate layer called Data
public class Context : DbContext
{
public Context() : base("EscolaContext")
{
}
public DbSet<Escola> Escolas { get; set; }
public DbSet<Turma> Turmas { get; set; }
public DbSet<Aluno> Alunos { get; set; }
public DbSet<Usuario> Usuarios { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<Escola>().HasKey(c => c.Id);
modelBuilder.Entity<Escola>().Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Escola>().Property(c => c.Nome).HasMaxLength(100);
modelBuilder.Entity<Escola>().Property(c => c.Cnpj).HasMaxLength(14);
modelBuilder.Entity<Turma>().HasKey(c => c.Id);
modelBuilder.Entity<Turma>().Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Turma>().Property(c => c.Nome).HasMaxLength(100);
modelBuilder.Entity<Aluno>().HasKey(c => c.Id);
modelBuilder.Entity<Aluno>().Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Aluno>().Property(c => c.Nome).HasMaxLength(100);
modelBuilder.Entity<Aluno>().Property(c => c.Matricula).HasMaxLength(20);
modelBuilder.Entity<Usuario>().HasKey(c => c.Id);
modelBuilder.Entity<Usuario>().Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Usuario>().Property(c => c.Login).HasMaxLength(20);
modelBuilder.Entity<Usuario>().Property(c => c.Senha).HasMaxLength(8);
modelBuilder.Entity<Turma>().HasRequired(c => c.Escola).WithMany(p => p.Turmas).HasForeignKey(p => p.IdEscola);
modelBuilder.Entity<Aluno>().HasRequired(c => c.Turma).WithMany(p => p.Alunos).HasForeignKey(p => p.IdTurma);
}
When executing the command Enable-Migrations
no error. But the database and tables were not created.