Я группирую некоторые данные вместе, чтобы отобразить его на первой странице (ASPX).System.InvalidCastException: невозможно лить объект типа «System.Linq.GroupedEnumerable
У меня есть следующий код: -
IEnumerable<ReportQuestion> questionSubjectGrps =
questionsBll.GetReportQuestions()
.Where(x => x.VersionId == iLatestVersion);
reportQuestionsList =
questionSubjectGrps.GroupBy(q => q.SubjectId,
(qid, qs) => qs.GroupBy(q => q.ParentId));
foreach (ReportQuestion reportQuestion in reportQuestionsList)
{
ReportQuestionsGuiDisplay reportQuestionsGuiDisplay =
new ReportQuestionsGuiDisplay();
reportQuestionsGuiDisplay.ParentQuestionTitle =
questionsBll.GetQuestionParents()
.FirstOrDefault(
x => x.QuestionParentId == reportQuestion.ParentId)
.QuestionParentTitle;
reportQuestionsGuiDisplay.ReportId = reportQuestion.ReportId;
reportQuestionsGuiDisplayList.Add(reportQuestionsGuiDisplay);
}
На переднем конце (ASPX), я следующее:
<% foreach (ReportQuestionsGuiDisplay report in reportQuestionsGuiDisplayList)
{%>
<div class="hrLightBlue"></div>
<div class="RPTContentTitle2">
<%= report.SubjectTitle %>
</div>
<div class="hrLightBlue"></div>
<%} %>
Однако я получаю следующее сообщение об ошибке:
Невозможно лить объект типа '
System.Linq.GroupedEnumerable``3[SCPerformance.Shared.Models.ReportQuestion,System.Nullable``1[System.Int32],SCPerformance.Shared.Models.ReportQuestion]
' для ввода 'SCPerformance.Shared.Models.ReportQuestion
'.
На какой линии вы получаете, что ошибка? –
в foreach (отчет ReportQuestionQuestion в reportQuestionsList), поскольку reportQuestionsList является IEnumerable>> –
Johann
Почему вы группируете в первую очередь? Что вы пытаетесь достичь здесь? –