Empty Migration in first Migration in aspcor.net 8

18 views Asked by At

This is my connection string :

     "ConnectionStrings": { "EvSefDBConnection": "Server=.;Database=evsef_db;Trusted_Connection=True;MultipleActiveResultSets=true\"\""

and with this context:

  public class EvSefDbContext : DbContext {
  public EvSefDbContext(DbContextOptions<EvSefDbContext> options) : base(options)
  { } }


 

and in program.cs I have this config:

builder.Services.AddDbContext<EvSefDbContext>(options =>{ options.UseSqlServer(builder.Configuration.GetConnectionString("EvSefDBConnection"));});

But after I add-migration Initial database it was created but both up and down is empty . I want just create my data base with out any table and model, I want just create data base in sql server.

this is empty migration:

  public partial class initial2db : Migration {
  /// <inheritdoc />
  protected override void Up(MigrationBuilder migrationBuilder)
  {

  }

  /// <inheritdoc />
  protected override void Down(MigrationBuilder migrationBuilder)
  {

  }

}

1

There are 1 answers

2
Martin Staufcik On

You need to add the entities into the context, otherwise they will not be generated.

public class EvSefDbContext : DbContext 
{
    public EvSefDbContext(DbContextOptions<EvSefDbContext> options) : base(options)
    { 
    } 

    public DbSet<MyFirstEntity> MyFirstEntities { get; set; }
    public DbSet<MySecondEntity> MySecondEntities { get; set; }
    ...

    // You will also need the following if using SQL Server:
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer("myrealconnectionstring");
    }
}