Generate model-based Migration (Entity Framework)

Asked

Viewed 80 times

1

I’m trying to generate a model-based Migration:

  [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; }

Only after executing the command: Add-Migration, is generated my Migration, but the function Up() empty. I need it to come already modeled, equal to 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; }
}

2 answers

0

Have you ever thought of using Fluent API to do the bank mapping I find more practical, something else checks your constructor and tries to pass the name of the bank like this:

public Context() : base("Default")

0

You need to add your table to your implementation of DbContext

public class DatabaseEntities : DbContext {
    public virtual DbSet<AcademicosMig> AcademicosMigs{ get; set; }
}
  • Mine looks like this: public class Context : Dbcontext { public Context() : base("name=Default") { } public virtual Dbset<Academicos> academicos { get; set; } } And yet I still can’t generate migraiton

Browser other questions tagged

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