My tables are structured as below:
Questions
id title
1 what is this?
Answers
id answer qid
1 an 1
I want to select the question and all the answers in one single row through LINQ?
How can i do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
In addition to Hasan’s answer, if you are using LinqToSql and your relationships are properly established, then the code should simply be:
Answers should then already be available to you through the property:
Since presumably you have an actual relationship defined between
question.Idandanswer.Qid.Update:
In response to OP’s comments, here is how you can get all the data back as one row:
Will return an object with the question and 3 answers. Obviously adding more answers requires tweaking this statement, since it’s flattened.