Streletz
Streletz

Reputation: 202

Create a migration for the model class

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.

Upvotes: 0

Views: 536

Answers (1)

Tiago Silva
Tiago Silva

Reputation: 2349

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

Upvotes: 2

Related Questions