MVC Code first data design

I am trying to create joins between 3 tables using MVC code first approach. My main table is the Request table. I need to be able to join these tables.  The requirements is going to build a multi check list box where multiple requirements may be checked. A request may have multiple requirements... I need help with the navigational properties

public partial class Request
    {
        public int ID { get; set; }

        [StringLength(10)]
        [Display(Name = "User Name")]
        public string UserName { get; set; }

       public DateTime? RequestDate { get; set; }

        public int? RequestRequirementId { get; set; }
    }

Open in new window

==================================================================================
public partial class Requirement
    {
        public int ID { get; set; }

        [Required]
        [StringLength(100)]
        public string Description { get; set; }
    }

Open in new window

===================================================================================
public partial class RequestRequirement
    {  
        public int ID { get; set; }
       
        public int RequestId { get; set; }
        
        public int RequirementId { get; set; }

        public virtual Requirement Requirement { get; set; }

        public virtual Request Request { get; set; }
    }

Open in new window

Natavia FinnieSenior Analyst Technical Focus ApplicationsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duy PhamFreelance IT ConsultantCommented:
I think you could use Linq Join in this case. See reference here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/join-clause.
0
Natavia FinnieSenior Analyst Technical Focus ApplicationsAuthor Commented:
I need help with the navigational properties
0
Duy PhamFreelance IT ConsultantCommented:
Oh, sorry that I didn't see the last sentence.

Maybe this:
public partial class Request
{
    [Key]
    public int ID { get; set; }
    ...
}

public partial class Requirement
{
    [Key]
    public int ID { get; set; }
    ...
}

public partial class RequestRequirement
{
    public int ID { get; set; }
    public int RequestId { get; set; }
    public int RequirementId { get; set; }

    [ForeignKey("RequestId")]
    public Request Request { get; set; }

    [ForeignKey("RequirementId")]
    public Requirement Requirement { get; set; }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Natavia FinnieSenior Analyst Technical Focus ApplicationsAuthor Commented:
Thank you!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.