我有以下内容:
var tests = await db.Tests
.Include(t => t.Exam)
.Where(t => t.TestStatusId == 1)
.Select(t => new TestDTO
{
ExamName = t.Exam.Name,
Id = t.TestId,
QuestionsCount = t.QuestionsCount,
Title = t.Title
})
.ToListAsync();
return Ok(tests);
即使特定测试没有匹配的考试,我怎样才能使它仍然返回测试?
答案 0 :(得分:0)
试试这个:
//first step
var tests = db.Tests
.Include(t => t.Exam)
.Where(t => t.TestStatusId == 1);
//next step
if(testc.Exam != null && testc.Exam.Count > 0)
{
testc = testc.Select(t => new TestDTO
{
ExamName = t.Exam.Name,
Id = t.TestId,
QuestionsCount = t.QuestionsCount,
Title = t.Title
});
}