如何加入两个可查询的查询

时间:2019-07-04 14:11:32

标签: c# linq iqueryable

我想连接两个易查询,两个都通过过滤两个条件来获得结果集,无论查询连接还是结果集连接我都想将结果作为内部连接 这是我的代码

我真的想做这样的事情

var joinedquery = query.Join(query2)


var query = filteredVehicle
                    .Join(VehiclePolicy, m => m.Id, n => n.VehicleId, (m, n) => new { m, n })
                    .Join(Policy, o => o.n.PolicyId, p => p.Id, (o, p) => new { o, p })
                    .Join(Contracti, q => q.p.ContractId, r => r.Id, (q, r) => new { q, r })
                    .Join(Insureri, s => s.r.InsurerId, t => t.Id, (s, t) => new { s, t })
                    .Join(ReinsurerContracti, u => u.s.r.ReinsurerContractId, v => v.Id, (u, v) => new { u, v })
                    .Join(Dealeri, w => w.u.s.q.p.DealerId, x => x.Id, (w, x) => new { w, x })
                    .Join(ContractExtensionPremium, y => y.w.u.s.q.p.ContractExtensionPremiumId, z => z.Id, (y, z) => new { y, z })
                    .Join(WarrantyType, b => b.z.WarrentyTypeId, c => c.Id, (b, c) => new { b, c })
                    .Join(Reinsureri, d => d.b.y.w.v.ReinsurerId, e => e.Id, (d, e) => new { d, e })
                    .Join(Bordx, f => f.d.b.y.w.u.s.q.p.BordxId, g => g.Id, (f, g) => new { f, g })

                    .Where(h => h.g.StartDate >= BordxStartDate && h.g.EndDate <= BordxEndDate)
                    .Select(yz => new
                    {
                        Insurer = yz.f.d.b.y.w.u.t.Id,
                        InsurerShortName = yz.f.d.b.y.w.u.t.InsurerShortName,
                        Reinsurer = yz.f.d.b.y.w.v.ReinsurerId,
                        ReinsurerName = yz.f.e.ReinsurerName,
                        UNRYear = yz.f.d.b.y.w.v.UWYear,
                        Dealer = yz.f.d.b.y.w.u.s.q.p.DealerId,
                        DealerName = yz.f.d.b.y.x.DealerName,
                        PolicyStatus = getpolicyStatus(yz.f.d.b.y.w.u.s.q.p.Id),
                        WarantyType = yz.f.d.c.WarrantyTypeDescription,
                        EarnPrecen = getErnPercent(yz.f.d.b.y.w.u.s.q.p.PolicyStartDate, yz.f.d.b.y.w.u.s.q.p.PolicyEndDate, yz.f.d.b.y.w.u.s.q.p.Premium)
                    }).ToList();

                var query2 = filteredClaims
                    .Join(VehiclePolicy, m => m.Id, n => n.VehicleId, (m, n) => new { m, n })
                    .Join(Policy, o => o.n.PolicyId, p => p.Id, (o, p) => new { o, p })
                    .Join(Contracti, q => q.p.ContractId, r => r.Id, (q, r) => new { q, r })
                    .Join(Insureri, s => s.r.InsurerId, t => t.Id, (s, t) => new { s, t })
                    .Join(ReinsurerContracti, u => u.s.r.ReinsurerContractId, v => v.Id, (u, v) => new { u, v })
                    .Join(Dealeri, w => w.u.s.q.p.DealerId, x => x.Id, (w, x) => new { w, x })
                    .Join(ContractExtensionPremium, y => y.w.u.s.q.p.ContractExtensionPremiumId, z => z.Id, (y, z) => new { y, z })
                    .Join(WarrantyType, b => b.z.WarrentyTypeId, c => c.Id, (b, c) => new { b, c })
                    .Join(Reinsureri, d => d.b.y.w.v.ReinsurerId, e => e.Id, (d, e) => new { d, e })
                    .Join(Bordx, f => f.d.b.y.w.u.s.q.p.BordxId, g => g.Id, (f, g) => new { f, g })

                    .Where(h => h.g.StartDate >= BordxStartDate && h.g.EndDate <= BordxEndDate)
                    .Select(yz => new
                    {
                        Insurer = yz.f.d.b.y.w.u.t.Id,
                        InsurerShortName = yz.f.d.b.y.w.u.t.InsurerShortName,
                        Reinsurer = yz.f.d.b.y.w.v.ReinsurerId,
                        ReinsurerName = yz.f.e.ReinsurerName,
                        UNRYear = yz.f.d.b.y.w.v.UWYear,
                        Dealer = yz.f.d.b.y.w.u.s.q.p.DealerId,
                        DealerName = yz.f.d.b.y.x.DealerName,
                        PolicyStatus = getpolicyStatus(yz.f.d.b.y.w.u.s.q.p.Id),
                        WarantyType = yz.f.d.c.WarrantyTypeDescription,
                        EarnPrecen = getErnPercent(yz.f.d.b.y.w.u.s.q.p.PolicyStartDate, yz.f.d.b.y.w.u.s.q.p.PolicyEndDate, yz.f.d.b.y.w.u.s.q.p.Premium)
                    });

0 个答案:

没有答案