Advertisement

Advertisement

Code First Approach k Thru Current model me new model add kaise add kare

How to add tables from models to ApplicationDbContext

Create Lesson class

public class Lesson { public int Id { get; set; } public string LessonName { get; set; }  

}

Modify the ApplicationDbContext as below

public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } public DbSet<Lesson> Lesson { get; set; } public DbSet<Instructor> Instructor { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<Lesson>().ToTable("Lesson"); modelBuilder.Entity<Instructor>().ToTable("Instructor");  

}

In the Package Manager Console, run the follow migration command: 

  1. add-migration addlesson
  2. update-database

 

Code First Approach k Thru Current model me new model add kaise add kare Code First Approach k Thru Current model me new model add kaise add kare Reviewed by Rikesh on June 30, 2023 Rating: 5

No comments:

Powered by Blogger.