1 回答
TA贡献1785条经验 获得超8个赞
我能够通过将其分解为三个独立的查询而不是一个查询来完成上述操作。我仍然很想知道社区中是否有人有办法将其作为一个查询来完成。
不管怎样,下面是我的代码。我能够使用 Responses 和 ResponseIssues 的正确行数更新 Questions Parent,并返回所有问题。
var question = await _dbContext.Questions
.Include(x => x.SurveySection)
.Include(x => x.Survey)
.Where(x => x.SurveyId == surveyId)
.OrderBy(x => x.Position)
.ToListAsync();
var responses = await _dbContext.Responses
.Where(x => x.SiteUserId == siteUserId &&
x.SurveyPeriodId == surveyPeriodId)
.ToListAsync();
var responseIssues = await _dbContext.ResponseIssues
.Where(x => x.SurveyPeriodId == surveyPeriodId &&
x.SiteUserId == siteUserId)
.ToListAsync();
foreach (var item in question)
{
var foundResponse = responses.Where(x => x.QuestionId == item.Id).ToList();
var foundResponseIssue = responseIssues.Where(x => x.QuestionId == item.Id).ToList();
if (foundResponse != null)
{
item.Responses = foundResponse;
}
if (foundResponseIssue != null)
{
item.ResponseIssues = foundResponseIssue;
}
}
- 1 回答
- 0 关注
- 81 浏览
添加回答
举报