linq到实体嵌套选择填写

时间:2012-02-24 18:08:23

标签: c# linq entity-framework linq-to-entities

我正在尝试将linq中的结果和嵌套结果返回给实体查询。

Orders[] orderlist =
(from m in db.Orders.Include("OrderLines")
    where
    areas.Contains(m.Area)
    && m.Branch == branch
    && (m.OrderStatus == "1" || m.OrderStatus == "4")
    && m.SpecialInstrs == string.Empty
    select m
HOW??---> m.OrderLines = m.OrderLines.Where(p => (p.LineType == "1" || p.LineType == "7") && p.MBomFlag != "C").ToArray()
).ToArray();

问题是当我真的只想要某些订单行时,include会返回每个订单的所有FK'd OrderLines。

我该怎么做?

Orders和OrderList都是由L2E和poco实体生成器生成的POCO实体。

1 个答案:

答案 0 :(得分:0)

您可以手动加入它们:

Orders[] orderlist = (from m in db.Orders
                      join p in db.Orderlines
                        on p.OrderId = m.Id
                      where areas.Contains(m.Area) 
                        && m.Branch == branch
                        && (m.OrderStatus == "1" || m.OrderStatus == "4")
                        && m.SpecialInstrs == string.Empty
                        && (p.LineType == "1" || p.LineType == "7")
                        && p.MBomFlag != "C"
                      select m).ToArray();