Entity Framework 7-migration nicht das erstellen von Tabellen

Arbeite ich mit meinem ersten Projekt mit Entity Framework 7 und bin Verbindung zu einem SQL Server, wo die Datenbank ist auch schon erstellt, aber es werden keine Tabellen in es noch nicht. Ich habe meine DbContext und eine Klasse angelegt, dann legen Sie eine DbSet<> in meinem Kontext. Ich lief die Befehle zum aktivieren von Migrationen und die Erstellung der ersten migration, dann rand der Befehl zum aktualisieren der Datenbank. Sah alles gut zu funktionieren, keine Fehler kam, aber wenn ich mir die Datenbank nur die EFMigraitonsHistory Tabelle erstellt wurde. Wenn ich mir die Klasse, die erstellt wurde für die erste migration es ist im wesentlichen leer. Was mache ich falsch?

Befehle, die ich verwende:

dnvm install latest -r coreclr
dnx ef migrations add MyFirstMigration
dnx ef database update

Kontext:

namespace JobSight.DAL
{
    public class JobSightDBContext : DbContext
    {
        public DbSet<NavigationMenu> NavigationMenu { get; set; }
    }
}

Tabelle Klasse:

namespace JobSight.DAL
{
    public class NavigationMenu
    {
        [Required, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Int16 ID { get; set; }

        public string ControllerName { get; set; }
        public string ActionName { get; set; }
        public string ExternalURL { get; set; }
        public string Title { get; set; }
        public Int16? ParentID { get; set; }

        public virtual NavigationMenu Parent { get; set; }
    }
}

Start.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<JobSightDBContext>(options =>
                {
                    options.UseSqlServer(Configuration["Data:JobSightDatabase:ConnectionString"]);
                });
    }

Klasse für die erste migration (automatisch generierte durch EF):

namespace JobSight.WebUI.Migrations
{
    public partial class Initial : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
        }
    }
}

Bearbeiten:
Nach tun, was Poke vorgeschlagen hat, das ist mein neues auto-generated migration. Die Tabelle ist noch nicht erstellt auf der Datenbank-Ebene obwohl.

namespace JobSight.WebUI.Migrations
{
    public partial class MyFirstMigration : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "NavigationMenu",
                columns: table => new
                {
                    ID = table.Column<short>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    ActionName = table.Column<string>(nullable: true),
                    ControllerName = table.Column<string>(nullable: true),
                    ExternalURL = table.Column<string>(nullable: true),
                    ParentID = table.Column<short>(nullable: true),
                    Title = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_NavigationMenu", x => x.ID);
                    table.ForeignKey(
                        name: "FK_NavigationMenu_NavigationMenu_ParentID",
                        column: x => x.ParentID,
                        principalTable: "NavigationMenu",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Restrict);
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable("NavigationMenu");
        }
    }
}
Schreibe einen Kommentar