Generate model-based migration (Entity Framework)

2

I'm trying to generate a migration based on a model:

  [Key]
    public int Id { get; set; }
    [MaxLength(100)]
    public string NomeInstituicao_Fundamental { get; set; }
    public string AnoInicio_Fundamental { get; set; }
    public string AnoFim_Fundamental { get; set; }
    [MaxLength(100)]
    public string NomeInstituicao_Superior { get; set; }
    public string AnoInicio_Superior { get; set; }
    public string AnoFim_Superior { get; set; }

    public Aluno aluno{ get; set; }

But after running the command: Add-Migration , my migration is generated, but the Up () function is empty. I need it to already be modeled, just like the attributes defined in my model.

 public partial class AcademicosMig : DbMigration
{
    public override void Up()
    {

    }

    public override void Down()
    {
    }
}

Context:

    public class Context : DbContext
{
    public Context() : base("name=Default")
    {
        this.Configuration.LazyLoadingEnabled = false;
        this.Configuration.ProxyCreationEnabled = false;
    }
    public  DbSet<Academicos> Academico_ { get; set; }
}
    
asked by anonymous 25.09.2018 / 20:18

2 answers

1

I've thought of using fluent API to do the mapping of the bank I find more practical, something else checks your constructor and tries to pass the name of the bank like this:

public Context() : base("Default")
    
26.09.2018 / 05:04
0

You need to add your table to your implementation of DbContext

public class DatabaseEntities : DbContext {
    public virtual DbSet<AcademicosMig> AcademicosMigs{ get; set; }
}
    
25.09.2018 / 20:24