C# 如何使用EF 6.1进行外部联接

C# 如何使用EF 6.1进行外部联接,c#,entity-framework,C#,Entity Framework,我有以下资料: 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,

我有以下资料:

 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);
我怎样才能使它在没有与特定测试匹配的测试的情况下仍然返回测试?

尝试以下方法:

//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
        });
        }

你们如何申报考试和考试?如果Test.Exam未标记为必填字段,EF应在其自身上使用左连接添加
DefaultIfEmpty()