我收到了这个问题:
from supply in context.Supplies
where
supply.AccountId == accountId
&& supply.Product.Requests.Any(r => r.WantToTrade && r.PotentialTradeSupplies.Any(p=>p.CanBeTraded))
select supply).Include(s => s.Product)
.ThenInclude(p=>p.Requests)
.ThenInclude(r=>r.PotentialTradeSupplies)
.ThenInclude(pts=>pts.Sizes)
.Include(s=>s.Product)
.ThenInclude(p=>p.Requests)
.ThenInclude(r=>r.Account)
.Include(s=>s.Product)
.ThenInclude(p=>p.Gender)
.Include(s=>s.Product)
.ThenInclude(p=>p.Category)
.Include(s => s.Product)
.ThenInclude(p => p.Division)
.Include(s=>s.Product)
.ThenInclude(p=>p.Availabilities)
.ThenInclude(pa=>pa.Sizes)
如果request.WantToTrade为false,查询将返回产品的所有请求。我只想要WantToTrade为真的请求。如何过滤掉这些?
答案 0 :(得分:0)
删除第一个Any()
过滤器就足够了,因此您的查询将变为
from supply in list
where supply.AccountId == accountId
&& supply.WantToTrade
&& supply.PotentialTradeSupplies.Any(p=>p.CanBeTraded)
select supply