C# Linq到实体:向子关系添加where条件

C# Linq到实体:向子关系添加where条件,c#,.net,linq,linq-to-entities,C#,.net,Linq,Linq To Entities,例如,我有一个客户列表,每个客户都有一个订单列表。现在,我想得到一个所有未付订单的客户列表(假设这是状态2)。连同那份客户名单,我还想有一份未付订单的名单 例如,我有: from c in mycontext.Customers.Include("Orders") select c 在何处或如何添加条件以查找状态==2的订单,以及如何将这些订单包括在客户列表中?尝试以下操作: from c in mycontext.Customers.Include("Orders") from order

例如,我有一个客户列表,每个客户都有一个订单列表。现在,我想得到一个所有未付订单的客户列表(假设这是状态2)。连同那份客户名单,我还想有一份未付订单的名单

例如,我有:

from c in mycontext.Customers.Include("Orders")
select c
在何处或如何添加条件以查找状态==2的订单,以及如何将这些订单包括在客户列表中?

尝试以下操作:

from c in mycontext.Customers.Include("Orders")
from order in c.Orders
where order.status == 2
select order
或者为什么不干脆这样做:

from order in mycontext.Orders
where order.status == 2
select order
否则

from c in mycontext.Customers.Include("Orders")
where c.Orders.Any(order => order.status == 2)
select c


使用.Any使我找到了正确的解决方案,谢谢!请注意,如果您还需要满足条件的子实体,则不能使用
Any()
,因为如果
订单的
任何
具有
order.status==2
,则将选择所有
订单。很抱歉,如果我恢复了一个旧的帖子,但我正在努力解决一个类似的问题,并认为这可能是解决方案,但对我来说不起作用。
from c in mycontext.Customers.Include("Orders")
let newObject = {
    Customer = c,
    NotPaidOrders = c.Orders.Where(order => order.status == 2).ToList()
}
where newObject.NotPaidOrders.Any()
select newObject