linq到嵌套的实体选择填充
本文关键字:选择 填充 实体 嵌套 linq | 更新日期: 2023-09-27 18:25:47
我试图在linq-to-entities查询中返回一个结果和一个嵌套结果。
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实体生成器。
您可以手动加入它们:
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();