开发者

Linq Query with Include Doesn't Appear to be Return Proper Results in EF 4.0

I'm using Entity Framework 4.0 and I'm running into a problem with the following query:

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开发者_如何学JAVA_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;

I'm trying to return a list of users containing a sub list of their orders, containing a sub list of the order line items (something like user->orders->order_line_items) as shown by the includes above - however whenever I call ToTraceString this query it shows only returning a list of users.

I've used Include before with no problems, not sure what I'm doing wrong this time.


Try:

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

Explanation here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜