C#C
C#4y ago
Luciferno

EF-Core data reference [Answered]

So for school we have to make a Restaurant management system.
Now I am working on Reservations with the following model
        [Key]
        public int ReservationID { get; set; }

        public string? FirstName { get; set; }

        public string? LastName { get; set; }

        public string? Adress { get; set; }

        public string? City { get; set; }

        public string? Email { get; set; }

        public int GuestsComing { get; set; }

        public DateTime? Date { get; set; }

        public TimeSpan? Time { get; set; }

        public List<Menu> ChoosenMenus { get; set; }

        public decimal FoodPrice { get; set; }

        public int UserFK { get; set; }

But the problem I encounter is that the list ChoosenMenus exists of Menus that are already saved in my database but when I make a post request it still tries to add the menu's

This is my DbContext regarding the Reservation model so far
        modelBuilder.Entity<Reservation>()
            .HasOne<UserInfo>()
            .WithMany()
            .HasForeignKey(x => x.UserFK);

So I somehow need to make a reference to the already exisiting menus instead of adding them but I dont really know how to
Was this page helpful?