ApplicationDbContext Not Existing For Model

RDoZZ

New member
Joined
Jun 30, 2022
Messages
4
Programming Experience
3-5
I am learning .Net and am making a hotel booking system but I get the error (The Type or namespace ApplicationDbContext could not be found) but the thing is I have an ApplicationDbContext class in my data directory. How do I access ApplicationDbContext for my model here?


Room.cs



C#:
  public class Room

    {

        public int Id { get; set; }

        public int Name { get; set; }

        public int Location { get; set; }

        public int Type { get; set; }

        public string[] Types => new string[] { "First Class", "Second Class", "Third Class" };



        [NotMapped]

        public virtual List<Room> Rooms => new ApplicationDbContext().Rooms.ToList();



        public virtual List<Room_Usage> Usages => new ApplicationDbContext().Room_Usage.ToList().where(x => x.Room_id == Id).toList();

    }




ApplicationDBContext.cs


C#:
public class ApplicationDbContext : IdentityDbContext

{

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)

        : base(options)

    {

    }

    public DbSet<hotel_reservation.Models.Guest>? Guest { get; set; }

    public DbSet<hotel_reservation.Models.Room>? Room { get; set; }

    public DbSet<hotel_reservation.Models.Room_Usage>? Room_Usage { get; set; }

}
 
Presence in a directory doesn't matter. Visibility of the file in your .csproj matters. Namespace that the class is declared in matters. Assembly that the class is in matters.
 

Latest posts

Back
Top Bottom