我有这两个问题:
第二个过滤了这些ID的结果。
var query = (from bk in context.BookKeeping
join bk12 in context.BookKeeping on bk.LetteringId equals bk12.LetteringId
into bk11
from bk1 in bk11.DefaultIfEmpty()
join bi2 in context.BillingInformation on bk1.BillingInformationId equals bi2.BillId
into bi1
from bi in bi1.DefaultIfEmpty()
where bk.LetteringId != null && bk.PaymentId != null && bk1.LetteringId != null
select bk.PaymentId).Distinct();
var query2 = from m in context.Movement
join p2 in context.Payment on m.PaymentId equals p2.Id
into p1
from p in p1.DefaultIfEmpty()
join pm2 in context.PaymentMode on p.PaymentModeId equals pm2.Id
into pm1
from pm in pm1.DefaultIfEmpty()
from ids in query
where ids.Value == p.Id
select m;
第二个查询的有趣部分如下:
from ids in query
where ids.Value == p.Id
我想知道我是否可以使它更紧凑,以及如何使用方法语法过滤条件列表。我知道我必须使用 SelectMany ,但不知道如何选择正确的重载。
TIA。
答案 0 :(得分:0)
我找到了解决方案:
var query2 = context.Movement.SelectMany(m => query1, (m, ids) => new { m, ids })
.Where(a => a.m.PaymentId == a.ids).Select(a => a.m);
我必须说第一个lamba的语法起初很奇怪!