child 的 parent object

Where on child's parent object

我正在尝试获取所有 object 其中孩子的 parentId 等于页面 ID。

这就是我想要做的:

public IEnumerable<Route> GetAll(int locationId)
{
    _db.Configuration.ProxyCreationEnabled = false;
    return _db.Routes.Include(o => o.ConnectionPointRoutes.Select(s => s.Segment))
            .Include(o => o.ConnectionPointRoutes.Select(c => c.ConnectionPoint)
            .Where( c => c.Location.LocationId == locationId)).ToList();
}

但我一直收到此错误:

An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code

Additional information: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.

有什么想法吗?

我最终这样做了:

    public IEnumerable<Route> GetAll(int locationId)
    {
        return _db.Routes
            .Include(o => o.ConnectionPointRoutes.Select(s => s.Segment))
            .Include(o => o.ConnectionPointRoutes.Select(c => c.ConnectionPoint))
            .Where(c => c.ConnectionPointRoutes.Select(s => s.ConnectionPoint.Location)
            .FirstOrDefault(q => q.LocationId == locationId).LocationId == locationId)
            .ToList();
    }