मैं List<QuestionsAndChoices>
को getAllQuestions()
विधि में वापस करने का प्रयास कर रहा हूं लेकिन मुझे यह त्रुटि मिल रही है
Cannot implicitly convert type 'System.Collections.Generic.List<System.Linq.IGrouping<int, HowWellDoYouKnowMeAPI.Models.models.QuestionsAndChoices>>' to 'System.Collections.Generic.List<HowWellDoYouKnowMeAPI.Models.models.QuestionsAndChoices>
सभी प्रश्न प्राप्त करें
public List<QuestionsAndChoices> getAllQuestions()
{
List<QuestionsAndChoices> questionsAndChoices1 = context.quizQuestionAndChoices.
Join(context.quizQuestions, QandC => QandC.QuizQuestions.QuizQuestionsId, qustions => qustions.QuizQuestionsId, (QandC, qustions) =>
new
{
QandC,
qustions
}).
Join(context.quizChoices, QandC1 => QandC1.QandC.QuizChoicesId, choices => choices.QuizChoicesId, (QandC1, choices) =>
new QuestionsAndChoices
{
QuestionId = QandC1.qustions.QuizQuestionsId,
Question = QandC1.qustions.Questions,
Choices = choices,
}).GroupBy(e => e.QuestionId).ToList();
return questionsAndChoices1;
}
QuestionsAndChoices
वर्ग
public class QuestionsAndChoices
{
public int QuestionId { get; set; }
public string Question { get; set; }
public List<QuizChoices> Choices { get; set; }
}
QuizQuestionAndChoices
वर्ग
public class QuizQuestionAndChoices
{
public int QuizQuestionAndChoicesID { get; set; }
public int QuizChoicesId { get; set; }
public int QuizQuestionsId { get; set; }
public QuizChoices quizChoices { get; set; }
public QuizQuestions QuizQuestions { get; set; }
}
quizQuestions
वर्ग
public class QuizQuestions
{
public int QuizQuestionsId { get; set; }
public string Questions { get; set; }
public List<QuizzerQCdetails> quizzerQCdetails { get; set; }
public List<QuizQuestionAndChoices> QuizQuestionAndChoices { get; set; }
}
QuizChoices
वर्ग
public class QuizChoices
{
public int QuizChoicesId { get; set; }
public string Choice { get; set; }
public List<QuizzerQCdetails> quizzerQCdetails { get; set; }
public List<QuizQuestionAndChoices> quizQuestionAndChoices { get; set;
}
मुझे इस तरह के आउटपुट की उम्मीद है
{
"questionId":1,
"question":"q1",
"choices":{
{
"quizChoicesId":1,
"choice":"1c1",
"quizzerQCdetails":null,
"quizQuestionAndChoices":null
},
{
"quizChoicesId":2,
"choice":"1c2",
"quizzerQCdetails":null,
"quizQuestionAndChoices":null
}
}
}
लेकिन मुझे यह आउटपुट मिल रहा है @IbraHimM.Nada
मैं उस कोड को पढ़ चुका हूं लेकिन मुझे इस तरह का आउटपुट मिलता है
{
"questionId":1,
"question":"q1",
"choices":{
{
"quizChoicesId":1,
"choice":"1c1",
"quizzerQCdetails":null,
"quizQuestionAndChoices":null
}
}
}
,
{
"questionId":1,
"question":"q1",
"choices":{
{
"quizChoicesId":2,
"choice":"1c2",
"quizzerQCdetails":null,
"quizQuestionAndChoices":null
}
}
}
1 उत्तर
निम्नलिखित का प्रयास करें:
List<QuestionsAndChoices> questionsAndChoices1 = (
from qandc in context.quizQuestionAndChoices
join quest in context.quizQuestions on qandc.QuizQuestionsId equals quest.QuizQuestionsId
join answers in context.quizChoices on qandc.QuizChoicesId equals answers.QuizChoicesId
select new { question = quest.Questions, answers = answers })
.GroupBy(x => x.question)
.Select(x => new QuestionsAndChoices()
{
Question = x.Key,
Choices = x.Select(y => y.answers).ToList()
}).ToList();
संबंधित सवाल
जुड़े हुए प्रश्न
नए सवाल
c#
C # (उच्चारण "तेज देखें") Microsoft द्वारा विकसित एक उच्च स्तरीय, सांख्यिकीय रूप से टाइप किया हुआ, बहु-प्रतिमान प्रोग्रामिंग भाषा है। C # कोड आमतौर पर Microsoft के .NET परिवार के टूल और रन-टाइम को लक्षित करता है, जिसमें .NET फ्रेमवर्क, .NET कोर और Xamarin अन्य शामिल हैं। C # या C # के औपचारिक विनिर्देश में लिखे गए कोड के बारे में प्रश्नों के लिए इस टैग का उपयोग करें।