简体   繁体   English

LINQ到实体嵌套选择填充

[英]linq to entities nested select fillout

I'm trying to return a result and a nested result in a linq to entities query. 我正在尝试将结果和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();

The problem is that the include returns all the FK'd OrderLines for each order when I really only want certain order lines. 问题是当我真的只想要某些订单行时,include会为每个订单返回所有FK'd OrderLines。

How do I do this? 我该怎么做呢?

Orders and OrderList are both POCO entities generated by L2E and the poco entity generator. Orders和OrderList都是L2E和poco实体生成器生成的POCO实体。

You can manually join them: 您可以手动加入他们:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM