C# - There was an error running selected code generator: Could not get the reflection type for DbContext

Viewed 590

When scaffolding a controller in Visual Studio 2019 ASP.NET Core 5 MVC web app, I get the following error:

There was an error running selected code generator: Could not get the reflection type for DbContext: EasyFlightNew.Data.ApplicationDbContext

Here is one of my models

public class Passenger
{
    // Passenger Class with the following attributes: PassengerNo, FirstName, SecondName, DateOfBirth
    [Key]
    [MaxLength(10), MinLength(10)]
    public int PassengerNo { get; set; }

    [Required]
    [Column("FirstName")]
    [Display(Name = "First Name")]

    [RegularExpression(@"^[a-zA-Z\s]{1,50}$", ErrorMessage = " Up to 50 uppercase and lowercase characters are allowed.")]
    public string FirstName { get; set; }

    [Required]
    [Column("SecondName")]
    [Display(Name = "Second Name")]
    [RegularExpression(@"^[a-zA-Z\s]{1,50}$", ErrorMessage = " Up to 50 uppercase and lowercase characters are allowed.")]
    public string SecondName { get; set; }

    [Required]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
    [Display(Name = "Date Of Birth")]
    [Column("DateOfBirth")]
    public System.DateTime DateOfBirth { get; set; } 

    // Navigation, Reference to other entities
    public ICollection<PassengerBooking> PassengerBookings { get; set; }
}

Here is my ApplicationDbContext:

namespace EasyFlightNew.Data
{
    public class ApplicationDbContext : IdentityDbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options) { }
        
        public DbSet<Passenger> Passengers { get; set; }
        public DbSet<Flight> Flights { get; set; }
        public DbSet<PassengerBooking> PassengerBookings { get; set; }
        public DbSet<Booking> Bookings { get; set; }
        public DbSet<User> Users { get; set; }
    }
}

I would really appreciate any help

0 Answers
Related