Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:51:35+00:00 2026-05-26T16:51:35+00:00

im just trying to make a join from two entities. the two entieties are

  • 0

im just trying to make a join from two entities.

the two entieties are as folows:

public partial class AnswerSet
{
    public int Id { get; set; }
    public string Ans { get; set; }
    public bool IsTrue { get; set; }
    public int QuestionId { get; set; }

    public virtual QuestionSet QuestionSet { get; set; }
}

and

public partial class QuestionSet
{
    public QuestionSet()
    {
        this.AnswerSets = new HashSet<AnswerSet>();
    }


    public int Id { get; set; }

    public string Quest { get; set; }

    public virtual ICollection<AnswerSet> AnswerSets { get; set; }
}

So, there are a question and an Answer Entity on the database. 1 Question has more answers (in my example 4). So now im tried this:

 var v1 = db.QuestionSets
    .Select(q => q)
    .Where(q=> q.Id == 11)
    .Join(db.AnswerSets, 
            q => q.Id, 
            a => a.QuestionId, 
            (a, q) => new { question = q });

So, now i have the following output when the expression is as above (see image 1):

Here i have just the Answers.
when i chage the expression to:

var v1 = db.QuestionSets
    .Select(q => q)
    .Where(q=> q.Id == 11)
    .Join(db.AnswerSets, 
            q => q.Id, 
            a => a.QuestionId, 
            (q, a) => new { question = q });

then i have the following output (see image 2): (just the question, but 4 times. as many answers i have.)

So my question is, how can i join these two entities, that the Answers are a set in the QuestionSet entity?

thank you

Image 1
Image 2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:51:35+00:00Added an answer on May 26, 2026 at 4:51 pm

    You want a group join (see http://msdn.microsoft.com/en-us/library/bb311040.aspx)

    var QAs =
        from q in db.QuestionSets
        join a in db.AnswerSets 
           on q.Id equals a.QuestionId into answers
        select new { Question = q, Answers = answers };
    

    In Extension Method syntax:

    var QAs = db.QuestionSets
        .GroupJoin(
             db.AnswerSets, 
             q => q.Id, 
             a => a.QuestionId,
             (q, answers) => new {Question = q, Answers = answers});
    

    Hope that helps

    PS. Use it like so:

    foreach (var qa in QAs)
    {
        Console.WriteLine("Question #{0} has {1} answers", 
             qa.Question.Id, qa.Answers.Count());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to understand how class generics work and this bit just doesnt make
I'm trying to show data from two related entities in a DataGridView. I know
I am trying to make a select statement and I just cant get it
I am just trying to make a vector, but it gives me a huge
I'm still picking up ObjC and I'm just trying to make sure I understand
I just went through trying to make an alarm clock app with local notifications
I am just messing around trying to make a game right now, but I
I'm trying to make a RLE (Run-Length Encoder) Programme just for characters. I read
I'm trying to make it working for quite some time,but just can't seem to
i'm trying to make a very simple YACC parser on Pascal language which just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.