我正在研究LINQ查询和部分目标,做一次SQL数据库调用来实现结果。我有许多问题可能有答案的集合。
我需要选择所有问题和答案集合,如果没有特定问题的答案,我仍然需要它。
代码只给我一个问题,哪个有答案但没有答案
var t3 = (Context.Answers
.Include(answer => answer.AnswerStatusType)
.Where(answer => Context.Questions.Where(q => q.profileId == ProfileId)
.Any(t => t.Id == answer.QuestionId)))
.GroupBy(
x => x.QuestionId,
x => x,
(key, g) => new
{
Question = key,
Answers = g.ToList(),
}
).ToList();
答案 0 :(得分:0)
你可能需要这样的东西:
var t3 =
(
from q in Context.Questions
where q.profileId == ProfileId
join a in Context.Answers on q.Id equals a.QuestionId into gas
select new
{
Question = q,
Answers = gas.ToList(),
}
).ToList();