Select in Include Repository Pattern Returning null

Select in Include Repository Pattern Returning null

我有一个如下所示的数据库模型:

  1. 投诉(T1)
  2. 监控投诉(T2)
  3. 监控笔记(T3)

我的 Class 每个看起来如下:

class Complaints{
//props

    public virtual ICollection<MONITORING> MONITORINGs { get; set; }
}


class Monitoring{
//props

    public virtual ICollection<MonitoringNotes> MONITORINGNotes { get; set; }
}

class MonitoringNotes{

//props

}

当我 运行 存储库获取所有数据时,我得到了所有数据

    public IEnumerable<Complaints> GetAll()
    {

        try
        {
            return _context.Complaints

                .Include(t => t.MONITORINGs)
                .OrderBy(t => t.FileNum)
                .ToList();
        }
        catch (Exception ex)
        {
            _logger.LogError("Could not get complaint with checklist", ex);
            return null;
        }
    }

但是当我用select将注释添加到监控时,它returns Null:

public IEnumerable<Complaints> GetAll()
    {

        try
        {
            return _context.Complaints

                .Include(t => t.MONITORINGs.Select(t3=>t3.MONITORINGNotes )
                .OrderBy(t => t.FileNum)
                .ToList();
        }
        catch (Exception ex)
        {
            _logger.LogError("Could not get complaint with checklist", ex);
            return null;
        }
    }

另外,当我输入 select 时,我得到了笔记的 Intellisense,所以我不认为它是我的实体。如果我正确使用 select 语句,有人可以指出正确的方向吗?我在许多有关包括 3 级关系的问题中使用了这个解决方案,例如:Entity Framework - Include Multiple Levels of Properties.

使用 then include 解决了我的问题。

public IEnumerable<Complaints> GetAll()
{

    try
    {
        return _context.Complaints

            .Include(t => t.MONITORINGs)
                    .ThenInclude(t3=>t3.MONITORINGNotes )
            .OrderBy(t => t.FileNum)
            .ToList();
    }
    catch (Exception ex)
    {
        _logger.LogError("Could not get complaint with checklist", ex);
        return null;
    }
}