Create a migration for the model class

c# entity-framework entity-framework-core

Question

There is a model:

public class Category
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]       
    public int Id { get; set; }
    [Required]
    [Display(Name ="Категория")]
    public string CategoryName { get; set; }
}

There is a DB context:

public class ApplicationDbContext : IdentityDbContext
{
    public DbSet<Category> Categories { get; set; }
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options):base(options)
    {
    }
}

How do I create a migration based on a model class? The Add-Migration Category command creates only an empty migration.

1
0
2/19/2019 3:08:25 PM

Accepted Answer

Entity framework command 'dotnet ef migrations add nameofmigration' will generate a migration with all the changes made to your DbSet models you defined on your context , if a previous migration already added all your changes then yes it will create an empty migration

2
2/19/2019 3:07:21 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow