© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
63 replies
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; }
        [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);
        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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Ef core seed (data)
C#CC# / help
12mo ago
Data retrieval EF-core
C#CC# / help
15mo ago
Can't install EF core tools [Answered]
C#CC# / help
4y ago