包含的Linq查询在EF 4.0中似乎没有返回正确的结果

本文关键字:返回 结果 查询 Linq EF 包含 | 更新日期: 2023-09-27 18:07:06

我正在使用实体框架4.0,我遇到了以下查询问题:

IQueryable<user> users = 
    from u in Entities.users.
        Include("orders_assigned").Include("orders_assigned.order_line_items")
    from o in u.orders_assigned
    where 
        o.status.Equals((int)OrderStatus.ReadyForInvestigation) &&
        o.assigned_to_user_id != 0
    from oli in o.order_line_items
    where 
        oli.line_item_type.Equals("service") ||
        oli.line_item_type.Equals("package_service")
    select u;

我试图返回包含其订单子列表的用户列表,包含订单行项目的子列表(类似于user->orders->order_line_items),如上面的include所示-然而,每当我调用ToTraceString此查询时,它只显示返回用户列表。

我以前使用过Include没有问题,不知道这次我做错了什么

包含的Linq查询在EF 4.0中似乎没有返回正确的结果

尝试:

IQueryable<user> users = ((ObjectQuery<user>)
    from u in Entities.users
    from o in u.orders_assigned
    where 
        o.status.Equals((int)OrderStatus.ReadyForInvestigation) &&
        o.assigned_to_user_id != 0
    from oli in o.order_line_items
    where 
        oli.line_item_type.Equals("service") ||
        oli.line_item_type.Equals("package_service")
    select u).Include("orders_assigned").Include("orders_assigned.order_line_items");

解释。