繁体   English   中英

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

[英]How can I do an outer join with EF 6.1

我有以下几点:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM