0
linqクエリにはうまくいきますが、正しいレコードが得られていないストアドプロシージャを変換しています。 ストアドプロシージャは、次のようになります。私が持っているLinqは外部結合を残し、多くのレコードに戻ってきたユニオンを返します
SELECT isnull(a.CertificationId, cc.CertificationId) as CertificationId,
isnull(a.cipcode, cc.CipCode) as CipCode,isnull(a.Credential, lc.Credential) as Credential,
lc.LicensingCertificationProgram, lc.IssuingOrganization, isnull(a.ab, '') as ab
FROM enrCertificationCipCodes CC INNER JOIN
lkpCertifications lc ON CC.CertificationId = lc.CertificationId
left join
(SELECT pc.CertificationId,
cc.CipCode,
lc.Credential,
lc.LicensingCertificationProgram,
lc.IssuingOrganization, ab = 'Yes',
pc.psn
FROM enrCertificationCipCodes CC INNER JOIN
lkpCertifications lc ON CC.CertificationId = lc.CertificationId
inner join (select * from enrProgramCertifications where PSN = @PSN) PC on cc.CertificationId = pc.CertificationId) as a on a.CertificationId = cc.CertificationId
where cc.CipCode = @CipCode
union
select pc.CertificationId as CertificationId, p.cipcode as CipCode, other as Credential,'' as LicensingCertificationProgram,
'' as IssuingOrganization, 'Yes' as ab
from (select * from enrProgramCertifications where CertificationId = '99999') pc join enrProgram p on pc.PSN = p.PSN
where p.CIPCode = @CipCode and p.PSN = @PSN
Union
select '99999' as CertificationId, @CipCode as CipCode, 'Other' as Credential,'' as LicensingCertificationProgram, '' as IssuingOrganization, '' as ab
order by ab desc, Credential
LINQクエリは、結果は私が左結合されたテーブルから複数の行を取得していますということです
var t = ((from a in LkpCertifications
join d in EnrProgramCertifications on a.CertificationId equals d.CertificationId into ad
from d in ad.DefaultIfEmpty()
join c in EnrCertificationCipCodes on a.CertificationId equals c.CertificationId
where c.CipCode == "52.1999"
select new {
CertificationId = a.CertificationId,
CipCode = c.CipCode,
Credential = a.Credential,
Licensing = a.LicensingCertificationProgram,
IssuingOrganization = a.IssuingOrganization,
Psn = d.PSN != null ? d.PSN : 0,
ab = d.PSN != null ? "Yes" : ""
})
.Union (from k in EnrProgramCertifications
join l in LkpCertifications on k.CertificationId equals l.CertificationId where k.PSN == 19480
select new{
CertificationId = k.CertificationId,
CipCode = "52.1999",
Credential = k.Other,
Licensing = l.LicensingCertificationProgram,
IssuingOrganization = l.IssuingOrganization,
Psn = k.PSN != null ? k.PSN : 0,
ab = k.PSN != null ? "Yes" : ""
})).ToList();
t.Dump();
です。 PSN番号で修飾して左結合テーブルから行を制限しようとすると、lkpCertificationsテーブルから結果が得られません。 lkpCertificationにはすべての認証が含まれており、enrProgramCertificationsは注文と注文詳細設定のように選択された証明書のみを保持します。
私は19480.
任意のアイデアのPSNで0 PSNと、単一の55レコードにのみ単一の項目54を取得する必要があります
ようなので、私の現在の結果が見えます問題?