Hi Sir,
I have below sql query.
insert into WfrpFarmReportsSubDetail
(MpciCoverageOID,RelatedMpciCoverageOID,AssociatedAipCode,AssociatedAipPolicyNumber,AssociatedAipLocationStateCode,
AssociatedAipLocationCountyCode,AssociatedAipCommodityCode,WrittenAgreement)
select wfrp_mc.OID,rel_mc_new.OID,wfrp.AssociatedAipCode,wfrp.AssociatedAipPolicyNumber,wfrp.AssociatedAipLocationStateCode,
wfrp.AssociatedAipLocationCountyCode,wfrp.AssociatedAipCommodityCode,wfrp.WrittenAgreement
from dbo.MpciPolicy wfrp_mp
inner join dbo.MpciCoverage wfrp_mc on wfrp_mp.OID=wfrp_mc.MpciPolicyOID
inner join dbo.WfrpFarmReportsSubDetail wfrp on wfrp.MpciCoverageOID=wfrp_mc.PreviousOID
inner join dbo.MpciCoverage rel_mc_old on wfrp.RelatedMpciCoverageOID=rel_mc_old.OID
inner join dbo.MpciCoverage rel_mc_new on rel_mc_old.OID=rel_mc_new.PreviousOID
left join dbo.WfrpFarmReportsSubDetail wfrp_ex on wfrp_ex.MpciCoverageOID=wfrp_mc.OID and wfrp_ex.RelatedMpciCoverageOID=rel_mc_new.OID
where wfrp_mp.ReinsuranceYear = @RY and wfrp_mc.CommodityCode = '0076'
and wfrp_mc.CommodityStatus < '7' and wfrp_mc.HasRelatedCoverage = '1' and wfrp.RelatedMpciCoverageOID is not null
and rel_mc_old.CommodityStatus < '7' and rel_mc_new.CommodityStatus < '7'
and wfrp_ex.OID is null
I am trying to write the above query using LINQ.
i am getting the error: the type of one of the expression in join is incorrect. type inference failed for group join.
can anyone suggest me the solution.
What i tried is:
var data = (from mp in mpciPolicyRepository.GetAll()
join wfrp_mc in mpciCoverageRepository.GetAll() on mp.OID equals wfrp_mc.MpciPolicyOID
join wfrp in wfrpFarmReportsSubDetailsRepository.GetAll() on wfrp_mc.PreviousOID equals wfrp.MpciCoverageOID
join rel_mc_old in mpciCoverageRepository.GetAll() on wfrp.RelatedMpciCoverageOID equals rel_mc_old.OID
join rel_mc_new in mpciCoverageRepository.GetAll() on rel_mc_old.OID equals rel_mc_new.PreviousOID
join wfrp_ex in wfrpFarmReportsSubDetailsRepository.GetAll()
on new { a=wfrp_mc.OID, b=rel_mc_new.OID } equals new { a=wfrp_ex.MpciCoverageOID, b=wfrp_ex.RelatedMpciCoverageOID }//
into wfrpcollection from subwfrp in wfrpcollection.DefaultIfEmpty()
where mp.ReinsuranceYear == reinsuranceYear && wfrp_mc.CommodityCode == "0076" &&
!MpciCommodityStatusCodeExtensions.CancelledMpciCommodityStatusCodes.Contains(wfrp_mc.CommodityStatus ?? 0)
&& wfrp_mc.HasRelatedCoverage == '1' && wfrp.RelatedMpciCoverageOID != null
&& rel_mc_old.CommodityStatus < '7' && rel_mc_new.CommodityStatus < '7'
&& subwfrp == null
select new WfrpFarmReportsSubDetailViewModel
{
MpciCoverageOID = wfrp_mc.OID,
RelatedMpciCoverageOID = rel_mc_new.OID,
AssociatedAipCode = wfrp.AssociatedAipCode,
AssociatedAipPolicyNumber = wfrp.AssociatedAipPolicyNumber,
AssociatedAipLocationStateCode = wfrp.AssociatedAipLocationStateCode,
AssociatedAipLocationCountyCode = wfrp.AssociatedAipLocationCountyCode,
AssociatedAipCommodityCode = wfrp.AssociatedAipCommodityCode,
WrittenAgreement = wfrp.WrittenAgreement,
}).ToList();
//on new { wfrp_ex.MpciCoverageOID, wfrp_ex.RelatedMpciCoverageOID } equals new { wfrp_mc.OID , rel_mc_new.OID }
wfrpFarmReportsSubDetailViewModel.AddRange(data);
Thanks.