Hi
How to insert the record automatically into the master tables automatically if there is no record while running the application. At the moment I am doing given way but it only works while running database migration time. I want to fill the record into master table for necessary drop down list .the record should be inserted only if there is no any record exist on the table VehicleStatus,VehicleType. Please help
public VehicleDBContext(DbContextOptions<VehicleDBContext> options) : base(options) { } public DbSet<Vehicles> Vehicles { get; set; } public DbSet<VehicleStatus> VehicleStatus { get; set; } public DbSet<VehicleType> VehicleType { get; set; } protected override void OnModelCreating(ModelBuilder builder) { builder.Entity<VehicleStatus>() .HasData(new { Id = 1, Status = "Active" }, new { Id = 2, Status = "Sold" }, new { Id = 3, Status = "Scrapped" }); builder.Entity<VehicleType>() .HasData(new { Id = 1, Category = "Car" }, new { Id = 2, Category = "Van" }, new { Id = 3, Category = "SUV" }); }